UILabel:
//文本标签 UILabel
self.label = [[[UILabelalloc] initWithFrame:CGRectMake(0, 80, 200, 30)]autorelease];
self.label.text = @"akgo";//设置文本内容
self.label.textAlignment =NSTextAlignmentCenter;//设置显示格式
self.label.textColor = [UIColorblueColor];//设置文本颜色
self.label.backgroundColor = [UIColoryellowColor];//设置背景颜色
self.label.font = [UIFontsystemFontOfSize:16];//设置文本字体及大小
self.label.numberOfLines = 1;//设置文本显示行数,0表示任意行,默认是1
self.label.lineBreakMode =NSLineBreakByTruncatingTail;//设置文本断行格式,默认NSLineBreakByTruncatingTail
[selfaddSubview:self.label];
//设置任意行
self.label.numberOfLines = 0;//任意行
self.label.lineBreakMode =NSLineBreakByWordWrapping;
self.label.text = @"俗话说“男怕入错行,女怕嫁错郎“,选择一个极具发展潜力的行业直接关系到个人的事业生涯!目前手机软件开发有两大阵营:苹果ios开发和安卓开发。苹果一直走高端路线,主要面向中高端市场,这类人消费能力高,购买力强,直接刺激ios软件的开发和扩增。而安卓主要面向中低端市场,这类人购买力低,导致大多数安卓手机软件免费下载,只能通过手机广告等业务赚取利润。随着苹果swift语言的推出,很多安卓开发人员转向了ios开发,进一步捍卫了苹果手机龙头老大的地位。选择ios开发成为了未来10年移动互联网黄金时代的主流。";
// 计算文本的高度
NSDictionary *attribute = @{NSFontAttributeName:self.label.font};
CGSize size = [self.label.textboundingRectWithSize:CGSizeMake(self.label.bounds.size.width,MAXFLOAT)
options: NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
attributes:attribute
context:nil].size;
CGRect rect = self.label.frame;
self.label.frame =CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, size.height);
//创建一个矩形按钮
self.btn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
self.btn.frame =CGRectMake(10, 30, 80, 40);//设置frame
self.btn.backgroundColor = [UIColoryellowColor];//设置背景色
self.btn.titleLabel.font = [UIFontsystemFontOfSize:14];//设置字体及大小
//设置标题
[self.btnsetTitle:@"按钮"forState:UIControlStateNormal];//正常时显示状态
[self.btnsetTitle:@"按钮按下"forState:UIControlStateHighlighted];//高亮时显示状态
[self.btnsetTitle:@"按钮选中"forState:UIControlStateSelected];//选中时显示状态
//设置标题颜色
[self.btnsetTitleColor:[UIColorblueColor] forState:UIControlStateNormal];//正常时显示状态
[self.btnsetTitleColor:[UIColorredColor] forState:UIControlStateHighlighted];//高亮时显示状态
[self.btnsetTitleColor:[UIColorgreenColor] forState:UIControlStateSelected];//选中时显示状态
//设置标题对齐方式
self.btn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentCenter;//水平左对齐,右对齐,居中
self.btn.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;//垂直上对齐,下对齐,居中
//设置按钮点击回调方法
[self.btnaddTarget:selfaction:@selector(buttonClicked:)forControlEvents:UIControlEventTouchUpInside];
//添加按钮到视图上
[selfaddSubview:self.btn];
UIActivityIndicatorView:
//用户等待提示视图 UIActivityIndicatorView
self.aiView = [[[UIActivityIndicatorViewalloc] initWithFrame:CGRectMake(20, 140, 30, 30)]autorelease];
self.aiView.backgroundColor = [UIColorclearColor];//设置背景透明
self.aiView.activityIndicatorViewStyle =UIActivityIndicatorViewStyleWhite;//设置样式
self.aiView.hidesWhenStopped = NO;//动画停止时是否隐藏,YES隐藏 NO不隐藏,默认是YES
self.aiView.color = [UIColorgreenColor];//设置前景色为绿色
[selfaddSubview:self.aiView];
BOOL isAnimate = [self.aiViewisAnimating];//判断动画是否正在进行
[self.aiViewstopAnimating];//停止动画
[self.aiViewstartAnimating];//开始动画
UISearchBar:
//搜索条 UISearchBar
self.searchBar = [[[UISearchBaralloc] initWithFrame:CGRectMake(10, 20, 300, 44)]autorelease];
self.searchBar.placeholder =@"搜索";//设置引导字符串
self.searchBar.delegate =self;//设置委托
[self.searchBarbecomeFirstResponder];//设置为第一响应
[selfaddSubview:self.searchBar];
self.searchBar.tintColor = [UIColorredColor];//设置光标和附加按钮颜色
self.searchBar.barTintColor = [UIColorbrownColor];//设置bar背景色(ios7.0以后可用)
self.searchBar.backgroundImage = [UIImageimageNamed:@"background"];//设置背景图片
self.searchBar.keyboardType =UIKeyboardTypeDefault;//设置键盘类型
self.searchBar.showsCancelButton =NO;//设置取消按钮
self.searchBar.showsBookmarkButton =YES;//设置书签按钮
self.searchBar.showsSearchResultsButton =YES;//设置搜索结果按钮