UI常用控件:
- UIButton 按钮
- UILabel 文本标签
- UITextField文本输入框
- UIImageView 图片显示
- UIScrollView 滚动的控件
- UITableView 表格
- UICollectionView 九宫格
- UIWebView 网页显示控件
- UIAlertView 对话框(中间弹框)
- UINavigationBar导航条
- UIPageControl 分页控件
- UITextView 能滚动的文字显示控件
- UIActivityIndicator 圈圈
- UISwitch 开关
- UIActionSheet 底部弹框
- UIDatePicker 日期选择器
- UIToolbar 工具条
- UIProgressView进度条
- UISlider滑块
- UISegmentControl 选项卡
- UIPickerView 选择器
注意: 红色表明最常用,蓝色代表一般,黑色代表几乎不用
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
- UIFont代表字体,常见创建方法有以下几个:
- + (UIFont *)systemFontOfSize:(CGFloat)fontSize; 系统默认字体
- + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; 粗体
- + (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; 斜体
UIImageView
UIImageView极其常用,功能比较专一:显示图片
UIImageView的常见属性
@property(nonatomic,retain)UIImage *image;
- ➢显示的图片
@property(nonatomic,copy)NSArray *animationImages;
- ➢显示的动画图片
@property(nonatomic)NSTimeInterval animationDuration;
- ➢动画图片的持续时间
@property(nonatomic)NSInteger animationRepeatCount;
- ➢动画的播放次数(默认是0,代表无限播放)
@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];