iOS基本常用控件总结(UIView,UILabel,UIButton,UIImageView)
2015-02-25 10:22
591 查看
UIView
//view的坐标区域(相对于父视图) @property (nonatomic) CGRect frame; //view的坐标区域(相对于自身,也就是说原点是0,0) @property (nonatomic) CGRect bounds; //view的中心点 @property (nonatomic) CGPoint center; //父视图 @property(nonatomic,readonly) UIView *superview; //所有的子视图 @property(nonatomic,readonly,copy) NSArray *subviews; //背影色 @property(nonatomic,copy) UIColor *backgroundColor; //透明度 @property(nonatomic) CGFloat alpha; //隐藏状态 @property(nonatomic,getter=isHidden) BOOL hidden; //在view上添加一个view - (void)addSubview:(UIView *)view; //在指定层面插入一个视图 - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; //在某个视图是下级插入一个新视图 - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; //在某个视图的上级插入一个新视图 - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; //自杀 - (void)removeFromSuperview; //修改2个视图的层级 - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2; //将某个视图移到最上层 - (void)bringSubviewToFront:(UIView *)view; //将某个视力移到最底层 - (void)sendSubviewToBack:(UIView *)view; //判断一个视图是否是另外一个视图的子视图(如果是同一个视图也会返回yes) - (BOOL)isDescendantOfView:(UIView *)view; //通过tag找view - (UIView *)viewWithTag:(NSInteger)tag; //子视图的范围是否可以超过自己(默认是no),如果设为yes超过的部分会不显示出来 @property(nonatomic) BOOL clipsToBounds; //【停靠模式】 //允许子视图跟随,默认就是yes @property(nonatomic) BOOL autoresizesSubviews; //随父视图变化的效果 @property(nonatomic) UIViewAutoresizing autoresizingMask;
UILabel
//UILabel : UIView //设置文字 @property(nonatomic,copy) NSString *text; //字体 @property(nonatomic,retain) UIFont *font; //文字颜色 @property(nonatomic,retain) UIColor *textColor; //阴影颜色 @property(nonatomic,retain) UIColor *shadowColor; //阴影坐标 @property(nonatomic) CGSize shadowOffset; //行数,默认是1,设为0后自动换行 @property(nonatomic) NSInteger numberOfLines; //对齐方式 @property(nonatomic) NSTextAlignment textAlignment; //换行方式 @property(nonatomic) NSLineBreakMode lineBreakMode; //它有这么多参数 typedef NS_ENUM(NSInteger, NSLineBreakMode) { /* What to do with long lines */ NSLineBreakByWordWrapping = 0, /* Wrap at word boundaries, default */ 以单词折断 NSLineBreakByCharWrapping, /* Wrap at character boundaries */ 以字符折断 //前2个参数失效了。 NSLineBreakByClipping, /* Simply clip */ 截取,没有省略号,显示到哪是哪 NSLineBreakByTruncatingHead, /* Truncate at head of line: "...wxyz" */ 省略号在前 NSLineBreakByTruncatingTail, /* Truncate at tail of line: "abcd..." */ 省略号在后 NSLineBreakByTruncatingMiddle /* Truncate middle of line: "ab...yz" */ 省略号在中间 } NS_ENUM_***AILABLE_IOS(6_0); //高亮颜色 @property(nonatomic,retain) UIColor *highlightedTextColor; //高亮状态 @property(nonatomic,getter=isHighlighted) BOOL highlighted; //可用状态 @property(nonatomic,getter=isEnabled) BOOL enabled; //拿到系统字体名称 (字体簇) NSArray * familyArray = [UIFont familyNames]; for (NSString * familyName in familyArray) { //拿到每一类字体 //拿到分类下得字体名称 NSArray * names = [UIFont fontNamesForFamilyName:familyName]; for (NSString * name in names) { NSLog(@"%@", name); } } //使用固定字体 label.font = [UIFont fontWithName:@"Helvetica" size:20]; //系统默认字体加黑 label.font = [UIFont boldSystemFontOfSize:20]; //系统默认字体斜体 label.font = [UIFont italicSystemFontOfSize:20];
UIButton
//UIButton : UIControl : UIView //button除了alloc init方法创建以外,系统封装了类方法,在以前非常实用,不过在ios7中这个方法的实用性大大下降了。 + (id)buttonWithType:(UIButtonType)buttonType; typedef NS_ENUM(NSInteger, UIButtonType) { //一般都直接用custom,然后自定义文字,图片,背景色等 UIButtonTypeCustom = 0, UIButtonTypeSystem NS_ENUM_***AILABLE_IOS(7_0), UIButtonTypeRoundedRect = UIButtonTypeSystem, //这三种都一样,在ios7中是没有任何样式的,以前圆角用的最多,在ios7中也失效了 UIButtonTypeDetailDisclosure, UIButtonTypeInfoLight, UIButtonTypeInfoDark, //这三种都差不多,是一个信息标记 UIButtonTypeContactAdd, //加号标记 }; //设置不同状态下的字体,字体颜色,背景图片 - (void)setTitle:(NSString *)title forState:(UIControlState)state; - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state; - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state; //状态最常用下面3个 UIControlStateNormal = 0, //默认 UIControlStateHighlighted = 1 << 0, //被点击时,(当按住按钮不放时就是这个状态) UIControlStateSelected = 1 << 2, //选中时(这个状态是得手动设置为选中或非选中) //给按钮添加一个点击事件 //第一个参数名是目标对象(也就是给谁发消息),第二个参数是传一个方法名,(注意要这目标对象里有这个方法,不然就挂了) - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; //最后一个参数一般用UIControlEventTouchUpInside,点击松开时触发 //和上一个对应,删除一个点击事件 - (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; //注意:刚开始非常容易把状态的参数UIControlState和点击事件的参数UIControlEvents弄混,看好一个是state(状态),一个是events(事件)
UIImageView
//UIImageView : UIView //除了用allco initWithFrame的方式创建,还可以用图片直接初始化,如果用图片直接初始化,记得设frame //UIImageView的高亮(highlighted)类似于UIButton的selected,是手动开关的。(图片的高亮用的不多) //用图片初始化 - (id)initWithImage:(UIImage *)image; //用图片和高亮图片初始化 - (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage //图片属性 @property(nonatomic,retain) UIImage *image; //高亮图片 @property(nonatomic,retain) UIImage *highlightedImage; //高亮状态(默认是非高亮) @property(nonatomic,getter=isHighlighted) BOOL highlighted; //动画的图片数组 @property(nonatomic,copy) NSArray *animationImages; //高亮状态下的动画图片数组 @property(nonatomic,copy) NSArray *highlightedAnimationImages; //动画间隔 @property(nonatomic) NSTimeInterval animationDuration; //动画循环次数,循环完以后会自动停止 @property(nonatomic) NSInteger animationRepeatCount; //开始动画 - (void)startAnimating; //手动结束动画 - (void)stopAnimating; //判断动画状态 - (BOOL)isAnimating; //这个属性是UIView的,但是一般情况下只有UIImageView才会用到 @property(nonatomic) UIViewContentMode contentMode;
相关文章推荐
- iOS个人整理06-第一周小结,常用控件UIView,UILabel,UIImageView,UIButton,UITextField
- iOS开发:常用的UIView控件——UILabel、UITextField、UIButton
- 学习IOS开发UI篇--UIView\UIButton\UILabel\UIImageView\UITextField
- UIButton UIImageVIew UIView UILabel 等控件设置一个圆角
- iOS开发:常用的UIView控件——UILabel、UITextField、UIButton【转】
- 01【iOS总结】UIView、UILabel、UITextField、UIButton 、目标动作机制(+UIAlertView、UIAlertController)
- UIView UILabel UITextField UIButton UIImageView 常用属性
- IOS--UIViewUIButtonUIImageView设置圆角、阴影、边框的方法
- IOS基本控件常用属性及方法(七)---UIView
- iOS开发——基本控件(UIButton,UILabel,UITextField,UISwitch,UISlider,UISegmentedControl)
- 【iOS基础控件- 5 】【demo】 超级猜图 <UIButton + UIImageView>
- 程序猿之路-----学习MJ视频总结1---UIImageView和UIButton的区别 、iOS懒加载
- iOS UIView控件的常用属性和方法的总结
- 程序猿之路-----学习MJ视频总结1---UIImageView和UIButton的区别 、iOS懒加载
- UITableView---iOS开发的常用控件使用总结
- [iOS基础控件 - 3.5] NSBundle, UIImageView和UIButton的区别, 模拟器和文档
- iOS 给UIView、UIImageView、UILabel添加点击事件
- UI基础-基础控件-0324-浏览图片案例与改进版(UILabel、UIButton、UIImageView的应用)
- IOS--UIViewUIButtonUIImageView设置圆角、阴影、边框的方法
- 【iOS开发-46】利用UIButton和UIImageView的区别分辨哪些控件有addTarget监听事件这个方法