1 一、UIView常见属性 2 3 1.frame 位置和尺寸(以父控件的左上角为原点(0,0)) 4 5 2.center 中点(以父控件的左上角为原点(0,0)) 6 7 3.bounds 位置和尺寸(以自己的左上角为原点(0,0)) 8 9 4.transform 形变属性(缩放、旋转) 10 11 5.backgroundColor 背景颜色 12 13 6.tag 标识(父控件可以根据这个标识找到对应的子控件,同一个父控件中的子控件tag不要一样) 14 15 7.hidden 设置是否要隐藏 16 17 8.alpha 透明度(0~1) 18 19 9.opaque 不透明度(0~1) 20 21 10.userInteractionEnabled 能否跟用户进行交互(YES能交互) 22 23 11.superview 父控件 24 25 12.subviews 子控件 26 27 13.contentMode 内容显示的模式 28 29 30 31 二、UIView常见方法 32 33 1.addSubview: 34 35 添加子控件,被添加到最上面(subviews中的最后面) 36 37 38 39 2.removeFromSuperview 40 41 从父控件中移除 42 43 44 45 3.viewWithTag: 46 47 父控件可以根据这个tag标识找到对应的子控件(遍历所有的子控件) 48 49 50 51 4.insertSubview:atIndex: 52 53 添加子控件到指定的位置 54 55 56 57 5.利用两个类方法执行动画 58 59 + (void)beginAnimations:(NSString *)animationID context:(void *)context; 60 61 /* ...需要执行动画的代码..*/ 62 63 + (void)commitAnimations; 64 65 66 67 6.利用block执行动画 68 69 /* 70 71 duration 动画持续时间 72 73 animations 存放需要执行动画的代码 74 75 completion 存放动画完毕后需要执行的操作代码 76 77 */ 78 79 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 80 81 82 83 三、UIControl 84 85 1.只要继承了UIControl,就能简单处理一些事件(点击事件、值改变事件) 86 87 88 89 2.继承了UIControl的子类: 90 91 UIButton、UISlider、UISwitch、UIDatePicker等等 92 93 94 95 3.当需要监听一个子控件事件的时候,解决步骤: 96 97 1> 先看它是否继承自UIControl 98 99 2> 再看它内部是否有delegate属性 100 101 102 103 4.常用属性 104 105 1> enabled 能否处理事件,跟UIView的userInteractionEnabled属性类似 106 107 2> contentVerticalAlignment 内容在垂直方向上的排布方式 108 109 3> contentHorizontalAlignment 内容在水平方向上的排布方式 110 111 112 113 5.常用方法 114 115 1> 添加监听器 116 117 /* 118 119 target 监听器对象 120 121 action 事件触发时所调用的方法,调用target的方法 122 123 controlEvents 事件类型 124 125 */ 126 127 - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 128 129 130 131 2> 删除监听器 132 133 // 删除监听器后,事件触发时就不会再通知监听器了,也就不会再调用target的action方法了 134 135 - (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 136 137 138 139 3> 获得所有的监听器对象 140 141 - (NSSet *)allTargets; 142 143 144 145 四、UILabel的常见属性 146 147 1.text 所显示的文本内容 148 149 2.textColor 文本颜色 150 151 3.font 字体 152 153 4.shadowColor 文字的阴影颜色 154 155 5.shadowOffset 阴影的偏差距离(width水平方向的偏差距离,正数右边、height垂直方向的偏差距离,正数下边) 156 157 6.textAlignment 设置文字的排布方式(偏左、偏右、居中) 158 159 7.numberOfLines 允许文字最多有几行(默认是1,如果为0,自动换行) 160 161 162 163 五、UIButton 164 165 1.常见属性 166 167 1> titleLabel 获取内部的UILabel对象 168 169 2> imageView 获取内部的UIImageView对象 170 171 172 173 2.常见方法 174 175 1> 设置内部UILabel显示的文本内容 176 177 // 设置按钮文本的时候不能 btn.titleLabel.text = @"4324324"; 178 179 - (void)setTitle:(NSString *)title forState:(UIControlState)state; 180 181 182 183 2> 设置内部UILabel的文字颜色 184 185 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state; 186 187 188 189 3> 设置内部UILabel的文字阴影颜色 190 191 - (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state; 192 193 194 195 4> 设置内部UIImageView的图片 196 197 // 设置内部UIImageView的图片不能:btn.imageView.image = [UIImage imagedName:@"0.png"]; 198 199 - (void)setImage:(UIImage *)image forState:(UIControlState)state; 200 201 202 203 5> 设置背景图片 204 205 - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state; 206 207 208 209 6> 下面两个方法需要交给子类去重写 210 211 // 返回内部UILabel的frame(位置和尺寸) 212 213 - (CGRect)titleRectForContentRect:(CGRect)contentRect; 214 215 // 返回内部UIImageView的frame(位置和尺寸) 216 217 - (CGRect)imageRectForContentRect:(CGRect)contentRect; 218 219 220 221 7> 下面这些方法可以获取不同状态下的一些属性值 222 223 - (NSString *)titleForState:(UIControlState)state; 224 225 - (UIColor *)titleColorForState:(UIControlState)state; 226 227 - (UIColor *)titleShadowColorForState:(UIControlState)state; 228 229 - (UIImage *)imageForState:(UIControlState)state; 230 231 - (UIImage *)backgroundImageForState:(UIControlState)state;
UI控件总结-UI初级
时光见证了成长,还很无知,我想一点点幼稚转为有知!