UI总结(二)
-
手势
状态:
longPress.state == UIGestureRecognizerStateBegan
pan.state == UIGestureRecognizerStateChanged
pan.state == UIGestureRecognizerStateEnded
注意:UIImageView 和UILabel 用户交互(userInteractionEnabled)默认为NO,需打开
1.轻拍
初始化:init
属性:
numberOfTapsRequired 点击几次触发
numberOfTouchesRequired 需要几个手指触发
2.长按
初始化:init
属性:
minimumPressDuration 长按几秒触发 默认0.5
allowableMovement 长按移动的距离 默认10像素
3.清扫
初始化:init
属性:
direction 方向 左右和上下不可同时使用
例如:
swipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
4.平移
初始化:init
5.捏合
初始化:init
pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
设置缩放倍数:
pinch.scale = 1;
6.旋转
初始化:init
rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
设置旋转弧度:
rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
7.屏幕边缘手势
初始化:init
属性:edge
screenEdgePan.edges =UIRectEdgeLeft;
-
UIViewController
1.UISwitch
初始化:init
属性:
onTintColor 开关内颜色(黄色区域)
屏幕快照 2016-07-22 下午8.54.11.png
tintColor 切换到关闭时的颜色(蓝色区域)
屏幕快照 2016-07-22 下午8.55.33.png
thumbTintColor 开关按钮(圆圈)颜色
屏幕快照 2016-07-22 下午8.54.11.png
判断开闭状态:
switch1.isOn ? @"YES" : @"NO"
switch1.on = YES;
[switch1 setOn:YES animated:YES];
绑定事件:
forControlEvents:UIControlEventValueChanged
2.UISlider
初始化:init
属性:
backgroundColor 背景色
value 滑动条所在当前值(.f)
minimumValue 滑块最小值(.f)
maximumValue 滑块最大值(.f)
thumbTintColor 滑块颜色
minimumTrackTintColor 滑块以左颜色
maximumTrackTintColor 滑块以右颜色
continuous NO:松手时才触发的方法
setThumbImage 显示滑块图片
minimumValueImage 最小值显示的图片
maximumValueImage 最大值显示的图片
setMinimumTrackImage 设置滑动条左侧图片
setMaximumTrackImage 设置滑动条右侧图片
3.UISegmentControl
初始化:
initWithItems: @[ , , ];
frame 不给值,系统会自动计算大小
momentary 没有选中效果
numberOfSegments 分段控制器Items的个数
insertSegmentWithTitle: atIndex: 增添对应下标的标题
remove 移除
setTitle:forSegmentAtIndex 修改对应下标的标题
setWidth: forSegmentAtIndex: 设置对应下标的宽度 默认0.0
setContentOffset: 设置对下标内容的偏移
setEnabled 是否可以被选中
selectedSegmentIndex 选中的下标
tintColor 文字及边框颜色
apportionsSegmentWidthsByContent 自动计算分段控制器段宽 默认: NO
绑定事件:
forControlEvents:(UIControlEventValueChanged)
4.pageControl
初始化: init
属性:
numberOfPages 页数
currentPage 当前页
hidesForSinglePage 当只有一页时隐藏
sizeForNumberOfPages: 获取到点的大小 CGSize类型
pageIndicatorTintColor 未选中的小圆点颜色
currentPageIndicatorTintColor 当前页小圆点颜色
defersCurrentPageDisplay 关闭page切换时间
updateCurrentPageDisplay 开启page切换事件
绑定事件:
forControlEvents:(UIControlEventValueChanged)]
-
ScrollView
继承于 UIResponder
属性
contentSize 滚动范围 CGSizeMake 默认为(0.0)
contentOffset 滚动偏移量 CGPointMake 默认为CGPointZero
contentInset 滚动区域四周的滚动范围 UIEdgeInsetsMake
directionalLockEnabled 锁定垂直或水平滚动
bounces 边缘回弹效果
alwaysBounceHorizontal 存在水平弹动效果
alwaysBounceVertical 存在垂直弹动效果
pagingEnabled 按页滚动
scrollEnabled 能否滚动
showsHorizontalScrollIndicator 显示水平滚动条
showsVerticalScrollIndicator 显示垂直滚动条
scrollIndicatorInsets 滚动条边距 UIEdgeInsetsMake
indicatorStyle 滚动条颜色
// UIScrollViewIndicatorStyleDefault,
// UIScrollViewIndicatorStyleBlack,
// UIScrollViewIndicatorStyleWhite
scrollsToTop 双击回顶部
keyboardDismissMode 键盘消失模式
minimumZoomScale 缩放最小
maximumZoomScale缩放最大
如果想进行视图的缩放,必须实现viewForZoomingInScrollView
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [scrollView.subviews firstObject];
}
scrollView.tracking 是否开始拖动 scrollView.isTracking
scrollView.dragging 是否正在拖动 scrollView.isDragging
scrollView.decelerating 是否正在减速scrollView.isDecelerating
添加代理
@interface ViewController ()<UIScrollViewDelegate>
@end
实现方法:
scrollViewWillBeginDragging: 滚动视图将要开始拖拽
scrollViewDidEndDragging: 滚动视图已经结束拖拽
scrollViewWillBeginDecelerating: 将要开始减速
scrollViewDidEndDecelerating: 已经结束减速
-
UINavigationController
继承于 UIViewController
初始化: init
属性:
title 标题(影响tabBar)
navigationItem.title 标题
titleView (将UISegmentedControl放在titleView上)
leftBarButtonItem:(自定义)
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"back" style:(UIBarButtonItemStylePlain) target:self action:@selector(comeBack:)];
rightBarButtonItem:(系统自带)
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemAdd) target:self action:nil];
BarButtonItems
UIBarButtonItem * barButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"1" style:(UIBarButtonItemStylePlain) target:self action:nil];
UIBarButtonItem * barButtonItem1 =[[UIBarButtonItem alloc]initWithTitle:@"2" style:(UIBarButtonItemStylePlain) target:self action:nil];
self.navigationItem.leftBarButtonItems = @[barButtonItem,barButtonItem1];
隐藏navigationBar
navigationController.navigationBarHidden
navigationController.navigationBar.hidden
barStyle
self.navigationController.navigationBar.barStyle
// UIBarStyleDefault = 0,
// UIBarStyleBlack = 1,
barTintColor背景颜色
半透明
navigationController.navigationBar.backgroundColor
不透明
navigationController.navigationBar.barTintColor
tintColor bar字体和边框颜色
navigationController.navigationBar.tintColor
translucent 半透明效果 NO时 原点从(0,64)开始
navigationController.navigationBar.translucent
与translucent 效果一样
edgesForExtendedLayout = UIRectEdgeNone;
push
[self.navigationController pushViewController:[[PushViewController alloc]init] animated:YES];
pop
[self.navigationController popViewControllerAnimated:YES];
-
界面通信
属性传值 从前往后
2.m
property(nonatomic,copy)NSString * passString;// 不要和系统重名
1.m
secVC.passString = _titleLabel.text;
协议传值
声明协议2.h -> 声明代理人2.h -> 签代理1,m -> 签协议1.m -> 实现方法1.m -> 传值2.m
声明协议:
@protocol passValue <NSObject>
// 默认 @required 必须实现
// @optional 可选
-(void)passValue:(NSString *)value;
@end
声明代理人:
#warning 声明代理人
@property(nonatomic,weak)id<passValue>delegate;
签代理:
secVC.delegate = self;
签协议:
#warning 签订协议
@interface FirstViewController ()<passValue>
实现方法:
#warning 实现协议方法
-(void)passValue:(NSString *)value{
NSLog(@"%@",value);
}
传值:
[self.delegate passValue:_tf.text];
-
UITabBarController
高度:49
设为根视图:
ViewController * vc1 = [[ViewController alloc]init];
vc1.view.backgroundColor = [UIColor yellowColor];
UINavigationController * navi1 = [[UINavigationController alloc]initWithRootViewController:vc1];
ViewController * vc2 = [[ViewController alloc]init];
vc2.view.backgroundColor = [UIColor redColor];
UINavigationController * navi2 = [[UINavigationController alloc]initWithRootViewController:vc2];
UITabBarController * tabBar = [[UITabBarController alloc]init];
tabBar.viewControllers = @[navi1,navi2];
_window.rootViewController = tabBar;
属性:
barTintColor bar背景色
tabBar.tabBar.barTintColor = [UIColor whiteColor];
tintColor bar 元素
tabBar.tabBar.tintColor = [UIColor blackColor];
tabBar.translucent 是否透明
tabBar.tabBar.translucent = YES;
tabBarItem.badgeValue 角标
vc1.tabBarItem.badgeValue = @"1000";
appearance 全局设置
UINavigationBar
[[UINavigationBar appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithWhite:0.038 alpha:1.000]}];
UITabBar
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:0.869 green:1.000 blue:0.541 alpha:1.000]];