iOS基本常用控件总结(UIView,UILabel,UIButton,UIImageView)

来源:互联网 发布:电脑上看淘宝直播 编辑:程序博客网 时间:2024/05/20 06:30

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_AVAILABLE_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_AVAILABLE_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;  



0 0
原创粉丝点击