创建设置页面 - UISegmented

时间:2015-06-03 04:45:55

标签: ios objective-c iphone xcode

我正在为我的应用创建设置菜单。我想使用UITableViewController,我在UISegmentedControl中添加了更改标签颜色(绿色,蓝色,红色)。虽然这仅在标签与SegmentedController位于同一页面时才有效。又名.h .m文件。我想控制第一个视图控制器上的标签。我到底该怎么做?如果我想添加振动拨动开关也是如此。如何使用第二个视图控制器操作访问第一个视图控制器标签?并且正在使A视图控制器+ TableViewcontroller成为这样做的正确方法,或者它应该是不同的。请帮忙。这是我的分段代码。

- (IBAction)colorController:(id)sender {

if (Controller.selectedSegmentIndex == 0) {

    //App title text color
     appTitle.textColor =  [UIColor colorWithRed:1.00 green:1.00 blue:0.00 alpha:1.0];

    //Background color when selected
    Controller.tintColor = [UIColor colorWithRed:1.00 green:1.00 blue:0.00 alpha:1.0];

    //The font of the selected
    NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:
                               [UIColor blackColor],NSForegroundColorAttributeName,
                               nil];
    [Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];



}
if (Controller.selectedSegmentIndex == 1) {

    //App title text color
    appTitle.textColor = [UIColor colorWithRed:0.00 green:0.66 blue:1.00 alpha:1.0];

    //Background color when selected
    Controller.tintColor = [UIColor colorWithRed:0.00 green:0.66 blue:1.00 alpha:1.0];

    //The font of the selected
    NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:
                               [UIColor whiteColor],NSForegroundColorAttributeName,
                               nil];
    [Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];

}
if (Controller.selectedSegmentIndex == 2) {

    //App title text color
    appTitle.textColor = [UIColor colorWithRed:0.98 green:0.22 blue:0.22 alpha:1.0];

    //Background color when selected
    Controller.tintColor = [UIColor colorWithRed:0.98 green:0.22 blue:0.22 alpha:1.0];


    //The font of the selected
    NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:
                               [UIColor whiteColor],NSForegroundColorAttributeName,
                               nil];
    [Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];
}
if (Controller.selectedSegmentIndex == 3) {

    //App title text color
    appTitle.textColor = [UIColor colorWithRed:0.15 green:0.82 blue:0.44 alpha:1.0];

    //Background color when selected
    Controller.tintColor = [UIColor colorWithRed:0.15 green:0.82 blue:0.44 alpha:1.0];

    //The font of the selected
    NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
    [Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];

}

如您所见,“appTitle”位于第一个视图控制器上。我怎么做它所以分段控制的状态保持我点击它的方式?一旦我回来,它总会重置。

1 个答案:

答案 0 :(得分:0)

在您所需的课程中实施协议。添加所需的委托方法&根据您的需要调用它。这样您就可以解决问题了。

参考教程链接

Apple Developer Guide

Delegation

Objective-C & Swift both