iOS各View的属性设置

UILabel

UITableView

背景色

1
tableView.backgroundColor = UIColor(hexString: "#f3f3f3", alpha: 0.6);

分割线

1
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;

內边距

1
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);

UITableViewCell

右侧标记

1
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator;

取消选中样式

1
cell.selectionStyle = UITableViewCellSelectionStyle.None;

UIButton

标题

1
2
3
4
statusButton.setTitle("已完成", forState: UIControlState.Normal);

secButton.setTitle("已评价", forState: UIControlState.Disabled);
secButton.enabled = false;

UINavigationBar(全局设置)

Swift示例

1
2
3
4
5
6
7
8
9
10
11
12
let appear = UINavigationBar.appearance();
//设置Item的样式
appear.tintColor = UIColor.whiteColor();
//设置bar的颜色
appear.barTintColor = UIColor(red: 39/255, green: 157/255, blue: 244/255, alpha: 1.0);
//设置背景色(不透明时没用,因为barTintColor在backgroundColor的上一层)
appear.backgroundColor = UIColor(red: 39/255, green: 157/255, blue: 244/255, alpha: 1.0);
//去掉navigationBar下的黑线
appear.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
appear.shadowImage = UIImage();
//设置标题样式
appear.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont.systemFontOfSize(18)];

OC示例

1
2
3
4
5
6
7
8
9
10
11
UINavigationBar *appear = [UINavigationBar appearance];
appear.tintColor = [UIColor clearColor];
appear.barTintColor = [UIColor colorWithRed:52.0/255 green:146.0/255 blue:233.0/255 alpha:1];
appear.backgroundColor = [UIColor colorWithRed:52.0/255 green:146.0/255 blue:233.0/255 alpha:1];
[appear setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
appear.shadowImage = [[UIImage alloc] init];

appear.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
[UIFont systemFontOfSize:18.0],NSFontAttributeName,nil
];

UITabBar(全局设置)

OC示例

1
2
UITabBar *tabbarAppear = [UITabBar appearance];
tabbarAppear.tintColor = [UIColor colorWithRed:56.0/255 green:173.0/255 blue:255.0/255 alpha:1];

UINavigationBar(页面设置)

设置标题颜色(OC)

1
2
3
4
5
6
//选择自己喜欢的颜色
UIColor * color = [UIColor whiteColor];
//这里我们设置的是颜色,还可以设置shadow等,具体可以参见api
NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
//大功告成
self.navigationController.navigationBar.titleTextAttributes = dict;

设置透明(Swift)

后两句是核心

1
2
3
4
5
//设置Navigationbar
self.navigationController.navigationBar.barStyle = UIBarStyle.BlackTranslucent;
self.navigationController.navigationBar.tintColor = UIColor.whiteColor();
self.navigationController.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController.navigationBar.shadowImage = UIImage();

UISearchBar(全局设置)

Swift示例

1
2
3
4
5
6
7
8
let searchBarAppear = UISearchBar.appearance();
//searchBarAppear.translucent = false;
searchBarAppear.backgroundColor = UIColor.clearColor();
searchBarAppear.tintColor = ZJ_Color.天空蓝;
searchBarAppear.barTintColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 1.0);
searchBarAppear.layer.borderColor = UIColor(hexString: "#ffffff")!.CGColor;
searchBarAppear.layer.borderWidth = 0;
searchBarAppear.backgroundImage = UIImage();