Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何更改xCode中选择器文本的颜色?_Ios_Objective C - Fatal编程技术网

Ios 如何更改xCode中选择器文本的颜色?

Ios 如何更改xCode中选择器文本的颜色?,ios,objective-c,Ios,Objective C,我终于在一个viewcontroller中加入了两个选择器,我意识到它们有点难看,因为背景是黑色的。如何更改选择器文本的颜色 这是我的整个视图控制器M // // ViewController.m // Repayment Calculator // // Created by Stewart Piper-Smith on 04/11/2015. // Copyright (c) 2015 Stewart Piper-Smith. All rights reserved. //

我终于在一个viewcontroller中加入了两个选择器,我意识到它们有点难看,因为背景是黑色的。如何更改选择器文本的颜色

这是我的整个视图控制器M

    //
//  ViewController.m
//  Repayment Calculator
//
//  Created by Stewart Piper-Smith on 04/11/2015.
//  Copyright (c) 2015 Stewart Piper-Smith. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()


@end

NSArray *_pickerViewArray;

NSArray *CareerViewArray;

@implementation ViewController



@synthesize button1, textbox1, textbox2, textbox3, startingsalary, repaymentlabel, debtlabel, startingrepayments, timetakentopayoffloan, realtimetakentopayoffloan, debtamounttextfield, annualrepaymentstextfield, monthlyrepaymentstextfield,weeklyrepaymentstextfield, payoffloantextfield, testlabel, annualrepaymentstest, totaldebtamounttest, writtenofflabel,payoffloanlabel,newlabel;


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// - (IBAction)button1Press:(id)sender {
//    [button1 setTitle:textbox1.text forState:UIControlStateNormal];
// }

//The start of the calculate button that starts the calculations.

-(IBAction)menucontactbuttonPress:(id)sender {

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error"
                                                                             message:@"Contact Form Coming Soon"
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    //We add buttons to the alert controller by creating UIAlertActions:
    UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
                                                       style:UIAlertActionStyleDefault
                                                     handler:nil]; //You can use a block here to handle a press on this button
    [alertController addAction:actionOk];
    [self presentViewController:alertController animated:YES completion:nil];

}

 -(IBAction)button1Press:(id)sender

{
    [self.view endEditing:YES];
    int x = ([textbox1.text intValue]);
    int y = ([textbox2.text intValue]);
    int q = ([textbox3.text intValue]);
    float startingsal = ([startingsalary.text intValue]);


    int debtamounttfield = ([debtamounttextfield.text intValue]);

    float annualrepayments = ([annualrepaymentstextfield.text floatValue]);

    //PROBLEM STARTS
    float p1 = debtamounttfield /annualrepayments;//([debtamounttextfield.text intValue]);

    if(isnan(p1) || isinf(p1)){
        p1 = 0.00;
    }

    //int a = ([annualrepaymentstextfield.text intValue]);
    //int b = ([debtamounttextfield.text intValue]);

    //[newlabel setText:[NSString stringWithFormat:@"%@", a/b]];

    [testlabel setText:[NSString stringWithFormat:@"%.01f",p1]];

    [totaldebtamounttest setText:[NSString stringWithFormat:@"%d", debtamounttfield]];

    [annualrepaymentstest setText:[NSString stringWithFormat:@"%@", annualrepaymentstextfield]];

    [payoffloantextfield setText:[NSString stringWithFormat:@"%.01f",  p1]];
    //PROBLEM ENDS

    [debtamounttextfield setText:[NSString stringWithFormat:@"£" "%i" , (x + y) * q]];

    int arp = (startingsal - 17335)*0.09;

    [annualrepaymentstextfield setText:[NSString stringWithFormat:@"£" "%i",  arp ]];

    if (arp < 0) {

        annualrepaymentstextfield.text = @"Written Off";

    }

    int monthlyrepayments = (startingsal - 17335)*0.09/12;

    [monthlyrepaymentstextfield setText:[NSString stringWithFormat:@"£" "%i",  monthlyrepayments]];

    if (monthlyrepayments < 0){

        monthlyrepaymentstextfield.text = @"Written Off";
    }

    int weeklyrepayments = (startingsal - 17335)*0.09/12/4;

    [weeklyrepaymentstextfield setText:[NSString stringWithFormat:@"£" "%i",  weeklyrepayments]];

    if (weeklyrepayments < 0){

        weeklyrepaymentstextfield.text = @"Written Off";
    }

    //Error Handling
    //Enter starting salary
    if ([annualrepaymentstextfield.text isEqualToString: @"Written Off"]) {

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Debt Written Off"
                                                                                 message:@"As it will take you longer than 30 years to pay off the loan, the debt would be written off."
                                                                          preferredStyle:UIAlertControllerStyleAlert];
        //We add buttons to the alert controller by creating UIAlertActions:
        UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
                                                           style:UIAlertActionStyleDefault
                                                         handler:nil]; //You can use a block here to handle a press on this button
        [alertController addAction:actionOk];
        [self presentViewController:alertController animated:YES completion:nil];


    }

    if ([startingsalary.text isEqualToString: @""]) {

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error"
                                                                                 message:@"Please enter your expected starting salary"
                                                                          preferredStyle:UIAlertControllerStyleAlert];
        //We add buttons to the alert controller by creating UIAlertActions:
        UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
                                                           style:UIAlertActionStyleDefault
                                                         handler:nil]; //You can use a block here to handle a press on this button
        [alertController addAction:actionOk];
        [self presentViewController:alertController animated:YES completion:nil];


    }

    //If course length is equal to 0
    if ([textbox3.text isEqualToString: @"0"]) {

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error"
                                                                                 message:@"Your course lenth cannot be 0 Years. Please enter a different value"
                                                                          preferredStyle:UIAlertControllerStyleAlert];
        //We add buttons to the alert controller by creating UIAlertActions:
        UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
                                                           style:UIAlertActionStyleDefault
                                                         handler:nil]; //You can use a block here to handle a press on this button
        [alertController addAction:actionOk];
        [self presentViewController:alertController animated:YES completion:nil];
    }


    //If course length text field is empty
    if ([textbox3.text isEqualToString: @""]){
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error"
                                                                                 message:@"Please enter your current course length"
                                                                          preferredStyle:UIAlertControllerStyleAlert];
        //We add buttons to the alert controller by creating UIAlertActions:
        UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
                                                           style:UIAlertActionStyleDefault
                                                         handler:nil]; //You can use a block here to handle a press on this button
        [alertController addAction:actionOk];
        [self presentViewController:alertController animated:YES completion:nil];


    }

    //time taken to pay off loan > 20 years
    int newtimetaken = [timetakentopayoffloan.text intValue];

    if (newtimetaken <= 20) {

        writtenofflabel.text = @"WO";
    }

}




-(IBAction)clearbutton:(id)sender {

    [textbox1 setText:[NSString stringWithFormat:@""]];

    [textbox2 setText:[NSString stringWithFormat:@""]];

    [textbox3 setText:[NSString stringWithFormat:@""]];


    [startingrepayments setText:[NSString stringWithFormat:@"Loan at start of repayments: "]];

    [startingsalary setText:[NSString stringWithFormat:@""]];

    [realtimetakentopayoffloan setText:[NSString stringWithFormat:@""]];

    [debtamounttextfield setText:[NSString stringWithFormat:@""]];

    [annualrepaymentstextfield setText:[NSString stringWithFormat:@""]];

    [monthlyrepaymentstextfield setText:[NSString stringWithFormat:@""]];

    [weeklyrepaymentstextfield setText:[NSString stringWithFormat:@""]];

    [payoffloantextfield setText:[NSString stringWithFormat:@""]];

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Cleared"
                                                                             message:@"All fields have now been cleared."
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    //We add buttons to the alert controller by creating UIAlertActions:
    UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
                                                       style:UIAlertActionStyleDefault
                                                     handler:nil]; //You can use a block here to handle a press on this button
    [alertController addAction:actionOk];
    [self presentViewController:alertController animated:YES completion:nil];
}



- (void)viewDidLoad {
    [super viewDidLoad];



    myLabel.text = @"Use the scroller above...";

    datePickerView.delegate = self;
    //CareerPickerView.dataSource = self;

    _pickerViewArray = @[@"Before September 2012",@"After September 2012"];



    CareerViewArray = @[@"1000",@"2000"];

    CareerPickerView.delegate = self;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if(pickerView == datePickerView)
    {
        NSString *dateSelected = [_pickerViewArray objectAtIndex:row];
        myLabel.text = dateSelected;
    }
    else if(pickerView == CareerPickerView)
    {
        NSString *careerSelected = [CareerViewArray objectAtIndex:row];
        startingsalary.text = careerSelected;
    }
}


-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    if(pickerView == datePickerView)
    {
        return _pickerViewArray.count;
    }
    else if(pickerView == CareerPickerView)
    {
        return CareerViewArray.count;
    }
    return 1;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if(pickerView == datePickerView)
    {
        return _pickerViewArray[row];
    }
    else if(pickerView == CareerPickerView)
    {
        return CareerViewArray[row];
    }
    return nil;
}






@end
//
//ViewController.m
//还款计算器
//
//由Stewart Piper Smith于2015年11月4日创建。
//版权所有(c)2015 Stewart Piper Smith。版权所有。
//
#导入“ViewController.h”
@界面视图控制器()
@结束
NSArray*_pickerviewaray;
NSArray*CareerViewArray;
@实现视图控制器
@综合按钮1、文本框1、文本框2、文本框3、开始工资、还款标签、债务标签、开始还款、支付时间、realtimetakentopayoffloan、realtimetakentopayoffloan、debtamounttextfield、年度还款字段、月度还款字段、周还款字段、支付字段、测试标签、年度还款字段、总债务测试、,writtenofflabel、payoffloanlabel、newlabel;
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
//-(iAction)按钮1按下:(id)发送器{
//[按钮1设置标题:textbox1.text for状态:uicontrol状态正常];
// }
//开始计算的“计算”按钮的开始。
-(iAction)菜单联系人按钮按:(id)发件人{
UIAlertController*alertController=[UIAlertController alertControllerWithTitle:@“错误”
信息:@“联系方式即将发布”
首选样式:UIAlertControllerStyleAlert];
//我们通过创建UIAlertActions向警报控制器添加按钮:
UIAlertAction*actionOk=[UIAlertAction actionWithTitle:@“Ok”
样式:UIAlertActionStyleDefault
handler:nil];//您可以在此处使用块来处理按下此按钮的操作
[alertController addAction:actionOk];
[self-presentViewController:alertController动画:是完成:无];
}
-(iAction)按钮1按下:(id)发送器
{
[自视图编辑:是];
int x=([textbox1.text intValue]);
int y=([textbox2.text intValue]);
int q=([textbox3.text intValue]);
float startingsal=([startingsalary.text intValue]);
int debtuamounttfield=([debtuamounttextfield.text intValue]);
浮动年还款=([AnnualReturnmentsTextField.text floatValue]);
//问题开始了
浮动p1=DebtAmountField/年度还款;/([debtamounttextfield.text intValue]);
if(isnan(p1)| isinf(p1)){
p1=0.00;
}
//int a=([AnnualReturnmentStextField.text intValue]);
//int b=([debtamountextfield.text intValue]);
//[newlabel setText:[NSString stringWithFormat:@“%@”,a/b]];
[testlabel setText:[NSString stringWithFormat:@“%.01f”,p1]];
[totaldebtamounttest setText:[NSString stringWithFormat:@“%d”,DebtaMountField]];
[年度还款测试设置文本:[NSString stringWithFormat:@“%@”,年度还款测试字段]];
[payoffloantextfield setText:[NSString stringWithFormat:@“%.01f”,p1]];
//问题结束了
[debtamounttextfield setText:[NSString stringWithFormat:@“£”“%i”“(x+y)*q]”;
int arp=(startingsal-17335)*0.09;
[年度还款StextField setText:[NSString stringWithFormat:@“£“%i”,arp]”;
if(arp<0){
年度还款stextfield.text=@“注销”;
}
国际月租金=(startingsal-17335)*0.09/12;
[monthlyrepaymentstextfield setText:[NSString stringWithFormat:@“£“%i”,monthlyrepayments]];
如果(月付款<0){
monthlyrepaymentstextfield.text=@“注销”;
}
int weeklyrepayments=(startingsal-17335)*0.09/12/4;
[weeklyrepaymentstextfield setText:[NSString stringWithFormat:@“£“%i”,weeklyrepayments]];
如果(每周付款<0){
weeklyrepaymentstextfield.text=@“注销”;
}
//错误处理
//输入起始工资
如果([AnnualReturnmentStextField.text IsequalString:@“注销”]){
UIAlertController*alertController=[UIAlertController alertControllerWithTitle:@“债务注销”
信息:@“由于还清贷款需要30年以上的时间,因此债务将被注销。”
首选样式:UIAlertControllerStyleAlert];
//我们通过创建UIAlertActions向警报控制器添加按钮:
UIAlertAction*actionOk=[UIAlertAction actionWithTitle:@“Ok”
样式:UIAlertActionStyleDefault
handler:nil];//您可以在此处使用块来处理按下此按钮的操作
[alertController addAction:actionOk];
[self-presentViewController:alertController动画:是完成:无];
}
如果([startingsalary.text isEqualToString:@”“])){
UIAlertController*alertController=[UIAlertController alertControllerWithTitle:@“错误”
信息:@“请输入您的期望起薪”
首选样式:UIAlertControllerStyleAlert];
//我们通过创建UIAlertActions向警报控制器添加按钮:
UIAlertAction*actionOk=[UIAlertAction actionWithTitle:@“Ok”
样式:UIAlertActionStyleDefault
handler:nil];//您可以在此处使用块来处理按下此按钮的操作
[alertController addAction:actionOk];
[self-presentViewController:alertController动画:是完成:无];
}
//如果
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        NSString *myTitle = @"my title";
        NSAttributedString *myAttString = [[NSAttributedString alloc] initWithString:myTitle attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
        return myAttString;
    }
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString *title = self.pickerArray[row];
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:NEON_GREEN}];

    return attString;

}