天天看點

設定UISegmentControl的文字屬性

以下代碼可以設定UISegmentControl的文字屬性。

UISegmentedControl *segmentedControl =.................;

        segmentedControl.layer.cornerRadius = 20;

    segmentedControl.clipsToBounds = YES;

    segmentedControl.tintColor =[UIColor redColor]; //設定顔色

    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],

                                             NSForegroundColorAttributeName: [UIColor whiteColor]};

    [segmentedControl setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//設定文字屬性

    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],

                                               NSForegroundColorAttributeName: [UIColor redColor]};

    [segmentedControl setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];

iOS