1. button 圖標(biāo)和文字位置設(shè)置
//文字
button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;```
//圖標(biāo)
[button setImage:[UIImage imageNamed:@"picture_name.png"] forState:UIControlStateNormal];
[button setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 65)];```
2. title的設(shè)置
self.tabBarItem.title = @"首頁"; //只在沒有嵌入navigation時(shí)生效
self.title = @"新聞"; //self.tabBarItem.title繼承自self.title;
self.navigationItem.title = @"導(dǎo)航"; //如果不設(shè)置,和self.title的內(nèi)容是一樣的```
#####3. NavigationBar中間文字屬性修改
self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont boldSystemFontOfSize:16]
};
#####4. Label部分文字變色
NSString *str = @"this is a string";
NSMutableAttributedString *noteStr =
[[NSMutableAttributedString alloc] initWithString:str];
NSRange redRange = NSMakeRange(0, 20);
[noteStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:redRange];
[label setAttributedText:noteStr];
[label sizeToFit];
#####5. UISwitch修改大小
//不能設(shè)置frame,只能用縮放比例
switch.transform = CGAffineTransformMakeScale(0.75, 0.75);
#####6. 透明NavigationBar
//寫法1
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
} - (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setShadowImage:nil];
[self.navigationController.navigationBar setBackgroundImage:nil
forBarMetrics:UIBarMetricsDefault];
}
//寫法2 - (void)setNavBarImg:(UINavigationBar *)navBar
{
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
// if iOS 5.0 and later
[navBar setBackgroundImage:[UIImage imageNamed:@"background_detail_bg1"]
forBarMetrics:UIBarMetricsDefault];
}
else
{
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:10];
[imageView setBackgroundColor:[UIColor clearColor]];
if (imageView == nil)
{
imageView =
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background_detail_bg1"]];
[imageView setTag:10];
[navBar insertSubview:imageView atIndex:0];
}
}
}
#####7. ScrollView頂部圖片下拉變大效果
//以下代碼作用是圖片高度改變驾诈,寬度也會(huì)改變,因此只需要修改圖片高度即可
ImageView.contentMode=UIViewContentModeScaleAspectFill;