ViewController控制整个界面的逻辑数据处理,界面仅仅用来获取数据个展示数据
IBAction 由按钮的 event ——》 touch up inside 事件链接
IBOutlet 标签链接生成类,提供属性,设置属性的类对象等。
新创建的storyboard需要勾选initial,不然整个storyboard无效
动画效果,
一。头尾式
二。block方式
//动画方式一。头尾式
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.5];
self.butImage.frame = orginFrame;
[UIViewcommitAnimations];
//动画方式二。Block
[UIViewanimateWithDuration:1animations:^{
self.butImage.frame= orginFrame;
}];
``
动态添加控件
//初始化按钮对象,并且设为Custom类型
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
//设置点击两种状态下的文字显示
[button setTitle:@"点我"forState:UIControlStateNormal];
[button setTitle:@"点我干嘛"forState:UIControlStateHighlighted];
//设置点击两种状态下的图片显示
UIImage *imageNormal = [UIImageimageNamed:@"d1"];
UIImage *imageHighlight = [UIImageimageNamed:@"d2"];
[button setBackgroundImage:imageNormal forState:UIControlStateNormal];
[button setBackgroundImage:imageHighlight forState:UIControlStateHighlighted];
//设置点击两种状态下的文字颜色
[button setTitleColor:[UIColorredColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColorblueColor] forState:UIControlStateHighlighted];
//设置frame,否则无位置不会显示
button.frame = CGRectMake(50, 50, 100, 100);
//设置监听
[button addTarget:selfaction:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
“`
UIView的常见属性
@property(nonatomic,readonly) UIView *superview;
获得自己的父控件对象
@property(nonatomic,readonly,copy) NSArray *subviews;
获得自己的所有子控件对象
@property(nonatomic) NSInteger tag;
控件的ID(标识),父控件可以通过tag来找到对应的子控件
// 根据tag来获取某个控件
UITextField txt = (UITextField )[self.view viewWithTag:1000];
@property(nonatomic) CGAffineTransform transform;
控件的形变属性(可以设置旋转角度、比例缩放、平移等属性)
---------------------------
@property(nonatomic) CGRect frame;
控件所在矩形框在父控件中的位置和尺寸(以父控件的左上角为坐标原点)
可以定义控件的位置(origin)和大小(size)
@property(nonatomic) CGRect bounds;
控件所在矩形框的位置和尺寸(以自己左上角为坐标原点,所以bounds的x、y一般为0)
可以定义控件的大小(size)
@property(nonatomic) CGPoint center;
控件中点的位置(以父控件的左上角为坐标原点)
可以定义控件的位置(center)
---------------------------
- (void)addSubview:(UIView *)view;
添加一个子控件view
- (void)removeFromSuperview;
从父控件中移除
- (UIView *)viewWithTag:(NSInteger)tag;
根据一个tag标识找出对应的控件(一般都是子控件)