漂亮的妹子來(lái)鎮(zhèn)貼~哈哈淹办!話(huà)不多說(shuō)眉枕,知識(shí)點(diǎn)走起!=课ā!
1.去掉導(dǎo)航欄下面的黑線
方法1(會(huì)影響導(dǎo)航欄的translucent透明屬性)
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
//視圖將要消失時(shí)取消隱藏
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
}```
######方法2
@property (nonatomic, weak) UIImageView *lineView;
//視圖加載完成獲取到導(dǎo)航欄最下面的黑線
-
(void)viewDidLoad {
[super viewDidLoad];//獲取導(dǎo)航欄下面黑線
_lineView = [self getLineViewInNavigationBar:self.navigationController.navigationBar];
}
//視圖將要顯示時(shí)隱藏
-
(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];_lineView.hidden = YES;
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
}
//視圖將要消失時(shí)取消隱藏
-
(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];_lineView.hidden = NO;
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
}
//找到導(dǎo)航欄最下面黑線視圖
-
(UIImageView *)getLineViewInNavigationBar:(UIView *)view
{
if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
return (UIImageView *)view;
}for (UIView *subview in view.subviews) {
UIImageView *imageView = [self getLineViewInNavigationBar:subview];
if (imageView) {
return imageView;
}
}return nil;
}
>2.修改navigationBar返回鍵的顏色
self.navigationController.navigationBar.barStyle = UIStatusBarStyleDefault;
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
>3.textField的屬性placeholder的字體顏色及大小
self.moneytextfield.placeholder = @"請(qǐng)輸入會(huì)員消費(fèi)金額";
[self.moneytextfield setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
[self.moneytextfield setValue:[UIFont systemFontOfSize:16.0] forKeyPath:@"_placeholderLabel.font"];
>4.給Label加中劃線或下劃線
UILabel *textLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 50, 100, 20)];
NSString *textStr = @"你好呀";
textLabel.font = [UIFont systemFontOfSize:15];
//中劃線
NSDictionary *attri = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
// //下劃線
// NSDictionary *attri = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attri];
textLabel.attributedText = att;
[self.view addSubview:textLabel];
>5 設(shè)置navigationItem的字體格式
// 字體大小19寂玲,顏色為白色
[nav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
>6.解決圖片壓縮變形的問(wèn)題
如果是imageView的話(huà)直接用
imageV.contentMode = UIViewContentModeScaleAspectFill;
imageV.layer.masksToBounds = YES;
button的話(huà)我也不知道為啥用著兩個(gè)屬性還是變形塔插,那就把button換成UIimageView加手勢(shì),再加上兩個(gè)屬性就行了
>6.自定義返回按鈕
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(backViewcontroller)];
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = -5;
self.navigationItem.leftBarButtonItems = @[fixedItem,leftItem];