您好,登錄后才能下訂單哦!
UI初級中的控件是UI學習的最基本的應用,下面是一些最基礎的控件的應用
#pragma mark -UILabel
- (void)_initLabel
{
UILabel *textLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 150, 250)];
textLable.backgroundColor = [UIColor grayColor];
//設置文本內容
textLable.text = @"good morning hehehehehe good morning hehehehehe";
//設置字體, systemFont使用系統的字體,大小10
textLable.font = [UIFont systemFontOfSize:16];
//設置粗體
textLable.font = [UIFont boldSystemFontOfSize:16];
//字體類 UIFont
NSArray *familyNames = [UIFont familyNames];
NSLog(@"familyNames is %@", familyNames);
textLable.font = [UIFont fontWithName:@"Zapf Dingbats" size:16];
//設置字體顏色
textLable.textColor = [UIColor orangeColor];
//設置文本對齊方式
textLable.textAlignment = NSTextAlignmentCenter;
//設置當前的顯示行數,默認是1行, 如果設為0,是自動換行
textLable.numberOfLines = 0;
//自動根據文本調整寬度和高度
[textLable sizeToFit];
// NSLog(@"textLabel is %@", textLable);
[self.window addSubview:textLable];
}
#pragma mark -UIButton
- (void)_initButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10, 180, 90, 44);
button.backgroundColor = [UIColor greenColor];
//設置顯示標題, 標題總是需要跟狀態綁定到一起的
// button.titleLabel.text = @"hehe"; //錯誤,不能這樣設置title
/*
typedef NS_OPTIONS(NSUInteger, UIControlState) {
UIControlStateNormal = 0,
UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set
UIControlStateDisabled = 1 << 1,
UIControlStateSelected = 1 << 2, // flag usable by app (see below)
UIControlStateApplication = 0x00FF0000, // additional flags available for application use
UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use
};
*/
[button setTitle:@"hehe" forState:UIControlStateNormal];
//設置高亮狀態下的title
// [button setTitle:@"haha" forState:UIControlStateHighlighted];
//設置選中狀態下的title
// [button setTitle:@"hihi" forState:UIControlStateSelected];
//設置按鈕是否選中
// button.selected = true;
//設置標題的字體
button.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//設置標題的顏色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
// [button setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。