前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS各View的属性设置

iOS各View的属性设置

作者头像
码客说
发布2019-10-22 14:09:11
1.4K0
发布2019-10-22 14:09:11
举报
文章被收录于专栏:码客

UILabel

UITableView

背景色
代码语言:javascript
复制
tableView.backgroundColor = UIColor(hexString: "#f3f3f3", alpha: 0.6);
分割线
代码语言:javascript
复制
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
內边距
代码语言:javascript
复制
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);

UITableViewCell

右侧标记
代码语言:javascript
复制
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator;
取消选中样式
代码语言:javascript
复制
cell.selectionStyle = UITableViewCellSelectionStyle.None;

UIButton

标题
代码语言:javascript
复制
statusButton.setTitle("已完成", forState: UIControlState.Normal);

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

UINavigationBar(全局设置)

Swift示例

代码语言:javascript
复制
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示例

代码语言:javascript
复制
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示例

代码语言:javascript
复制
UITabBar *tabbarAppear = [UITabBar appearance];
tabbarAppear.tintColor  = [UIColor colorWithRed:56.0/255 green:173.0/255 blue:255.0/255 alpha:1];

UINavigationBar(页面设置)

设置标题颜色(OC)

代码语言:javascript
复制
//选择自己喜欢的颜色
UIColor * color = [UIColor whiteColor];
//这里我们设置的是颜色,还可以设置shadow等,具体可以参见api
NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
//大功告成
self.navigationController.navigationBar.titleTextAttributes = dict;

设置透明(Swift)

后两句是核心

代码语言:javascript
复制
//设置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示例

代码语言:javascript
复制
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();
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-11-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • UILabel
  • UITableView
    • 背景色
      • 分割线
        • 內边距
        • UITableViewCell
          • 右侧标记
            • 取消选中样式
            • UIButton
              • 标题
              • UINavigationBar(全局设置)
              • UITabBar(全局设置)
              • UINavigationBar(页面设置)
              • UISearchBar(全局设置)
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档