StoryBoard 可视化界面布局注意点

使用 ScrollView 进行自动布局

解决方案:可以在 ScrollView 上添加一个唯一的子视图,大小和 ScrollView 一样,然后所有原来计划添加到 ScrollView 上的控件,都添加到子视图上面。

实现步骤

  1. 在 Controller 自带的 View 里面添加一个 ScrollView,约束距离为(0,0,0,0);

  2. 在 ScrollView 里面添加子视图 View ,约束 ScrollView 的距离为(0,0,0,0);

  3. 在下面设置约束的4个按钮的第二个,如果想要上下滑动,则选择 Horizontal Center in Container, 并打上对勾,(如果想要左右滑动就选择 Vertical Center in Container, 同时实现左右上下则全不选);

  4. 然后设置 View 的高度 Height(或者宽度 Width),这个高度或者宽度就是运行后 Scroller 的 ContentSize ;

动态设置高度或者宽度

将 View 的高度或者宽度设置成属性,然后重写 -(void)updateViewConstraints 方法,在调用 super 之后动态的设置 高度 这个约束的 constant 属性。

使用xcode storyboard设置按钮圆角方法

在 sb 中点击右侧指示器的第三个下的 “User Defined Runtime Attribute” 添加 layer.cornerRadius 的值。
-> 在代码中:self.button.layer.cornerRadius = 10;

设置 navigationController 标题的颜色

NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:BASECOLOR, NSForegroundColorAttributeName,nil];
[self.navigationController.navigationBar setTitleTextAttributes:attributes];

设置 navigationItem 的左按钮 (非自定义)

// 设置navigationItem的左按钮
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_common_return"] style:UIBarButtonItemStylePlain target:self action:@selector(leftNavBtnAction)];
leftItem.tintColor = BASECOLOR; //图片的颜色需要单独设置,图片相当于一个蒙版
self.navigationItem.leftBarButtonItem = leftItem;

在 sb 中设置所有的 UINavigationBar 的统一色调

先在 UINavigationController 的页面点击查看属性显示器(右侧栏第四个)设置 Bar Tint 的颜色,就可以将全部的 bar 设置成同一个颜色,然后如果要想bar 的按钮也跟bar 同一颜色的话,还需要将其的 Background 设置成 Clear Color ,这样在子页面的按钮上设置 Clear Color 才会看到跟 bar 上的同一颜色。

如果要想设置 UInavigationBar 上的 UIView 控件,需要在 wAny hAny 模式下将 UIView 放在右上角的位置,其他模式将不能正常显示 UIView 的大小与位置。