iOS UIView的常见属性
来源:互联网 发布:网络拓扑图图片 编辑:程序博客网 时间:2024/05/21 11:37
一 UIVIew 常见属性
1.frame 位置和尺寸(以父控件的左上角为原点(0,0))
2.center 中点 (以父控件的左上角为原点(0,0))
3.bounds 位置和尺寸(以自己的左上角为原点 (0,0))
4.transform 形变属性(缩放,旋转)
5.backgroundColor 背景颜色
6.tag标识(父控件可以根据这个标识找到对应的子控件,同一个父控件中的子控件不要一样)
7.hidden 设置是否要隐藏
8.alpha 透明度(0~1);
9.opaque 不透明度(0~1);
10.userInteractionEnabled 能否跟用户进行交互(YES 能交互)
11.superView 父控件
12.subviews 子控件
13.contentMode 内容显示的模式 拉伸自适应
二.UIView常见方法
1.addSubview
添加子控件,被添加到最上面(subviews中的最后面)
2.removeFromSuperview
从父控件中移除
3.viewWithTag:
父控件可以根据这个tag标识找到对应的控件(遍历所有的子控件)
4.insertSubview:atIndex:
添加子控件到指定的位置
5.利用两个类方法来执行动画的两个方法
+(void) beginAnimations:(NSString *)animationID context:(void *)context;
/**..需要执行动画的代码..**/
+(void) commitAnimations;
6.利用blok执行动画
/*
duration 动画持续时间
animations 存放需林执行动画的代码
completion 存放动画完毕后需要执行的操作代码
*/
+ (void) animateWithDuration:(NSTimeInterval) duration animations:(void (^)(void))animations completion:(void(^)) (BOOL finished) completion
三.UIControl
1.只要继承UIControl ,就能简单地处理事件(点击事件,值改变事件)
2.继承了UIControl的子类
UIButton.UISlider.UISwitch .UIDatePicker 等等
3.当需要监听了一个子控件时间的时候,解决步骤:
1>.先看它是否继承自UIControl
2>.再看它内部是否有delegate属性
4.常用属性
1>enabled 能否处理事件
2>contentVerticalAlignment 内容在垂直方向上的排布方式
3>contentHorizontalAlignment 内容在水平方向上的排布方式
5.常用方法
1> 添加监听器
/*
target 监听器对象
action 事件触发时所调用的方法,调用target的方法
*/
-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
2> 删除监听器
//删除监听器后,事件触发时就不会再通知监听器了,也就不会再调用target的action方法了
-(void roemoveTarget:(id)target action:](SEL)action forControlEvents:](UIControlEvents) controlEvents);
3>获得所有的监听器对象
-(NSSet *) allTargets;
四,UILabel
1.常见属性
1>text 所显示的文本内容
2>textColor 文本颜色
3> font 字体
4> shadowColor 文字的阴影颜色
5> shadowOffset 阴影的偏差距离(width水平方向的偏差距离,height垂直方向的念头距离,正数下边)
6> textAlignment 设置文字的排布方法(偏左,偏右,居中).
NSTextAlignmentLeft为向左对齐
NSTextAlignmentCenter为居中对齐
NSTextAlignmentRight为向右对齐
7>numberOfLines 允许文字最多有几行数(如果为0,自动换行).
label.adjustsFontSizeToFitWidth = YES;
adjustFontSizeToFitWidth方法可实现文本自动根据label大小自动调整字体尺寸,直到文本的大小达到了自己设置的label文本尺寸最大、最小值与字符串的最大最小值,要使用这个方法还有一个很大的限制就是只有在numberOfLines设置为" 1 "时才能用
[label sizeToFit]; ( label自适应高度 )
label文本省略方式的设置
label.lineBreakMode =NSLineBreakByCharWrapping;
其中lineBreakMode可选值为
linBreakMode enum{
NSLineBreakByWordWrapping = 0,//保留整个单词,以空格为边界
NSLineBreakByCharWrapping,//保留整个字符
NSLineBreakByClipping,//以边界为止
NSLineBreakByTruncatingHead,//省略开头,以省略号代替
NSLineBreakByTruncatingTail,//省略结尾,以省略号代替
NSLineBreakByTruncatingMiddle//省略中间,以省略号代替
}
五.UIButton
//.UISlider .UISwitch .UIDatePicker等等
1.常见属性
1>titleLabel 获取内部的UILabel 对象
2>imageView 获取内部的UIImageView对象
// 能够定义的button类型有以下6种,
// typedef enum {
// UIButtonTypeCustom = 0, 自定义风格
// UIButtonTypeRoundedRect, 圆角矩形
// UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
// UIButtonTypeInfoLight, 亮色感叹号
// UIButtonTypeInfoDark, 暗色感叹号
// UIButtonTypeContactAdd, 十字加号按钮
// } UIButtonType;
[button setTitle:@"点击" forState:UIControlStateNormal];
/* forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现*/
//以下是几种状态
// enum {
// UIControlStateNormal = 0, 常规状态显现
// UIControlStateHighlighted = 1 << 0, 高亮状态显现
// UIControlStateDisabled = 1 << 1, 禁用的状态才会显现
// UIControlStateSelected = 1 << 2, 选中状态
// UIControlStateApplication = 0x00FF0000,当应用程序标志时
// UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管
// };
2.常见方法
1>设置内部UILabel显示的文本内容
//设置按钮文本的时候不能 btn .titleLabel.text = @"4324324";
- (void)setTitle:(NSString *)title forState:(UIControlState)state; // default is nil. title is assumed to be single line
2> 设置内部UILabel的文字颜色
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)stateUI_APPEARANCE_SELECTOR; // default if nil. use opaque white
3>设置内部UILabel的文字阴影颜色
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)stateUI_APPEARANCE_SELECTOR; // default is nil. use 50% black
4>设置内部UIImageView的图片
- (void)setImage:(UIImage *)image forState:(UIControlState)state; // default is nil. should be same size if different for different states
5>设置内部UIImageView的图片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)stateUI_APPEARANCE_SELECTOR; // default is nil
6>下面两个方法需要交给子类去重写
//返回没物控部UILabel的frame (位置和尺寸)
-(CGRect)titleRectForContentRect:(CGRect)contentRect;
//返回内部UIImage的尺寸和位置
-(CGRect)imageRectForContentRect:(CGRect) contentRect;
7>下面这些方法可以获取不同状态下的一些属性
- (NSString *)titleForState:(UIControlState)state; // these getters only take a single state value
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIColor *)titleShadowColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
内容转自:http://www.cnblogs.com/jackluo/p/3901244.html
- iOS UIView的常见属性
- UIView的常见属性
- UIView的常见属性
- UIView的常见属性
- UIView的常见属性
- UIView的常见属性
- iOS开发 UIView常见属性
- iOS学习笔记之四--UIView的常见属性
- iOS学习笔记-005.UIView的常见属性、方法
- iOS UIView的属性
- IOS-UIView的常见方法
- [iOS] UIView的clipsTobounds属性
- ios UIView的clipsTobounds属性
- ios--UIView的contentStretch属性
- 【iOS】UIView的autoresizingMask属性
- ios UIView的常用属性
- iOS UIView的clipsTobounds属性
- UIView的常见属性和方法
- 汇编语言-[BX]和loop指令
- nyoj914Yougth的最大化【二分+贪心】
- Golang学习笔记 (一)
- poj 2406 Power Strings
- 凸优化中的数学基础知识(范数篇一)内积,欧式范数
- iOS UIView的常见属性
- 各种元素水平垂直居中
- 阿里无线前端性能优化指南 (Pt.1 加载期优化)
- Android 中解决图片加载OOM 之 bitmap 压缩显示,压缩上传
- 按钮的样式
- Spring横切面(advice),增强(advisor),切入点(PointCut)
- php字符串函数理解
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest D】【模拟 讨论】Boulevard 人流行走看是否相交 beautiful code
- HDU 4771 Stealing Harry Potter's Precious [BFS]