UI常用控件:
注意: 红色表明最常用,蓝色代表一般,黑色代表几乎不用
UILabel
UILabel极其常用,功能比较专一:显示文字
UILabel的常见属性:
@property(nonatomic,copy) NSString *text;
@property(nonatomic,retain)UIFont *font;
@property(nonatomic,retain)UIColor *textColor;
@property(nonatomic) NSTextAlignment textAlignment;
@property(nonatomic)NSInteger numberOfLines;
@property(nonatomic) NSLineBreakMode lineBreakMode;
UIFont
UIImageView
UIImageView极其常用,功能比较专一:显示图片
UIImageView的常见属性
@property(nonatomic,retain)UIImage *image;
@property(nonatomic,copy)NSArray *animationImages;
@property(nonatomic)NSTimeInterval animationDuration;
@property(nonatomic)NSInteger animationRepeatCount;
@property(nonatomic)UIViewContentMode contentMode;
设置图片的模式
有以下模式:
UIViewContentModeRedraw, // 重新绘制 (核心绘图) drawRact
//带有Scale,标明图片有可能被拉伸或压缩
UIViewContentModeScaleToFill, // 完全的压缩或拉伸
// Aspect 比例,缩放是带有比例的
UIViewContentModeScaleAspectFit, //宽高比不变 Fit适应(显示整张图片)
UIViewContentModeScaleAspectFill, //宽高比不变 Fill填充(显示部分图片,填充image大小)
//不带有Scale,标明图片不可能被拉伸或压缩
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
UIImageView的常见方法
- (void)startAnimating; //开始动画
- (void)stopAnimating; //停止动画
- (BOOL)isAnimating; //是否正在执行动画
UIImageView设置frame的四种方法
// 设置frame的方式
// 方式一
UIImageView *imageView = [[UIImageViewalloc] init];
imageView.image = [UIImageimageNamed:@"1"];
// imageView.frame = CGRectMake(100, 100, 267, 400);
// imageView.frame = (CGRect){{100, 100},{267, 400}};
// 方式二
UIImageView *imageView = [[UIImageView alloc] init];
// 创建一个UIImage对象
UIImage *image = [UIImageimageNamed:@"1"];
// 设置frame
imageView.frame =CGRectMake(100,10, image.size.width, image.size.height);
// 设置图片
imageView.image = image;
// 方式三
// 创建一个UIImage对象
UIImage *image = [UIImage imageNamed:@"1"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100,10, image.size.width, image.size.height)];
imageView.image = image;
// 方式四
// 创建一个UIimageview对象
// 注意: initWithImage默认就有尺寸--->图片的尺寸
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
// 改变位置
// imageView.center = CGPointMake(200, 150);
imageView.center =CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5);
[self.viewaddSubview:imageView];