- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的 Controller 上有 UISegmentedControl
。当我第一次打开它时,哪种色调效果很好。但是在按下后退按钮时,我将关闭 Controller 。当重新打开同一个 Controller 时,UISegmentedControl
的色调会消失。请帮忙。提前致谢。
headerSegment = [[UISegmentedControl alloc] initWithItems:segmentItemsArray];
headerSegment.selectedSegmentIndex = 0;
headerSegment.apportionsSegmentWidthsByContent = YES;
headerSegment.layer.borderWidth = 0;
headerSegment.layer.masksToBounds = NO;
UIFont *font = [UIFont systemFontOfSize:16];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[headerSegment setTitleTextAttributes:attributes
forState:UIControlStateNormal];
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [ApplicationColors skyBlueColor], NSFontAttributeName : [UIFont systemFontOfSize:16]} forState:UIControlStateSelected];
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [ApplicationColors segmentNormalColor], NSFontAttributeName : [UIFont systemFontOfSize:16]} forState:UIControlStateNormal];
headerSegment.layer.borderColor = [UIColor clearColor].CGColor;
headerSegment.tintColor = [UIColor whiteColor];
headerSegment.backgroundColor = [ApplicationColors lightGrayBackgroundColor ];
headerSegment.translatesAutoresizingMaskIntoConstraints = NO;
[headerSegment addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
[contentHolderView addSubview:headerSegment];
最佳答案
尝试使用以下代码,(它对我有用)
// ViewController.m
#import "ViewController.h"
@interface ViewController () {
UISegmentedControl * headerSegment;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self addsegmentcontrol];
}
-(void)addsegmentcontrol{
headerSegment = [[UISegmentedControl alloc] initWithItems:@[@"One", @"Two", @"Three"]];
headerSegment.selectedSegmentIndex = 0;
headerSegment.apportionsSegmentWidthsByContent = YES;
headerSegment.layer.borderWidth = 0;
headerSegment.layer.masksToBounds = NO;
UIFont *font = [UIFont systemFontOfSize:16];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[headerSegment setTitleTextAttributes:attributes
forState:UIControlStateNormal];
[headerSegment setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor greenColor], NSFontAttributeName : [UIFont systemFontOfSize:16]} forState:UIControlStateSelected];
[headerSegment setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont systemFontOfSize:16]} forState:UIControlStateNormal];
headerSegment.layer.borderColor = [UIColor clearColor].CGColor;
headerSegment.tintColor = [UIColor whiteColor];
headerSegment.backgroundColor = [UIColor lightGrayColor];
headerSegment.translatesAutoresizingMaskIntoConstraints = YES;
//[headerSegment addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:headerSegment];
headerSegment.frame = CGRectMake(0, 200, 320, 44);
[self.view layoutIfNeeded];
}
这是示例结果:
关于ios - UISegmentedControl 在解散后更改色调颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49357197/
我试图通过 unionSpatialPolygons 溶解内部多边形来生成六边形 map 的轮廓。或 aggregate职能。我得到了不溶解的杂散十六进制......一个显示问题的虚拟示例: # gr
我使用 AVPlayerViewController 在我的应用中播放短视频。 如果在用户在我的应用中播放视频之前有一个应用在后台播放音频,我希望在我的视频播放器关闭后恢复另一个应用的后台音频播放。我
我有三个 Controller 与 segues 相连。 Controller 一是 MyNotif, Controller 二是 AddNotif, Controller 三是 SelectInte
在我学习 Swift 3 和 Xcode 8 的过程中,我现在感到困惑或不知道何时使用正确的切换方法。要取消你解雇,返回你回去但后退按钮可以解雇吗? 哪一个是内存使用方面的最佳实践? @IBActio
我一直在尝试使用 Storyboards 关闭模态,但从阅读旧的 beta 版本来看,这些模态似乎已损坏。我尝试添加 header 以允许我从 Obj-C 端放松,但仍然没有。 这是我的swift文件
我是一名优秀的程序员,十分优秀!