码迷,mamicode.com
首页 > 其他好文 > 详细

[BS] 小知识点总结

时间:2016-04-26 19:08:06      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

1.

UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"MainTitle"]]; //initWithImage方法的好处是创建的imageView和图片的尺寸一样

2.

//UI层级,tabBar上的按钮的确是UITabBarButton类型,但是这个类是私有的不让用,故不能调[view isKindOfClass:[UITabBarButton class]

        if (![view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {

            continue;//如果不是这个类,直接跳过后面的代码,继续判断下一个

        }

3.

实例方法: [obj class]          类方法: [Class class];

WZLog(@"实例方法:%@,类方法:%@",[self class],[UITabBarItem class]);

4.

   //使用代码设置图片的渲染模式

     UIImage *image = [UIImage imageNamed:@"tabBar_essence_click_icon"];

     UIImage *renderImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//原始照片不渲染

     vc01.tabBarItem.selectedImage = renderImage;

5.

//更换TabBar底部条 @property(nonatomic,readonly) UITabBar *tabBar

    WZTabBar *tabBar = [[WZTabBar alloc]init];

    //self.tabBar = tabBar; 报错,readonly不能赋值,采用KVC赋值

    [self setValue:tabBar forKey:@"tabBar"];

6.

+ (void)initialize { //涉及appearance的设置要写在initialize中,此方法只在该类第一次被使用时才调用。

  UITabBarItem *item = [UITabBarItem appearance];

    [item setTitleTextAttributes:attr forState:UIControlStateNormal];

    [item setTitleTextAttributes:selectAttr forState:UIControlStateSelected];//注意此处为UIControlStateSelected,不能写成Highlighted

}

    //原理是:setTitleTextAttributes:forState: 函数后面有备注UI_APPEARANCE_SELECTOR,可以通过 [Class appearance] setTitleTextAttributes: forState: ]; 来同一设置字体颜色。

7.

UIButton *btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];

    [btnLeft setBackgroundImage:[UIImage imageNamed:@"MainTagSubIcon"] forState:UIControlStateNormal];

    [btnLeft setBackgroundImage:[UIImage imageNamed:@"MainTagSubIconClick"] forState:UIControlStateHighlighted];

    //注意必须设置btnLeftframe或者size

    btnLeft.size = btnLeft.currentBackgroundImage.size;

//自定义导航按钮时,事件应传给btnLeft;如果使用initWithTitle:target:action:方法初始化,可以把事件传给BarButtonItem

    [btnLeft addTarget:self action:@selector(tagSubClick) forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btnLeft];

8.

//设置发布按钮的frame

    CGFloat btnW = btnPublish.currentBackgroundImage.size.width;

    CGFloat btnH = btnPublish.currentBackgroundImage.size.height; //currentBackgroundImage属于UIImage:NSObject,不属于UIView,重写UIView(Frame)对UIImage不管用,UIImage自己就有.size属性。不能换成btnPublish.currentBackgroundImage.height;

9.

//xibsb加载的控件时,会调用此方法,纯代码定义继承UIView类初始化时不会调

- (instancetype)initWithCoder:(NSCoder *)aDecoder{

    NSLog(@"%s",__FUNCTION__);

    if (self = [super initWithCoder:aDecoder]) {

    }

    return self;

}

//纯代码定义UI控件类的实际初始化方法

- (instancetype)initWithFrame:(CGRect)frame{

if (self = [super initWithFrame:frame]) {

    }

    return self;

}

10.

//initWithFrame中设定frame,会被如下方法重新布局

- (void)layoutSubviews{

[super layoutSubviews];

}

//viewDidLoad完了调viewWillAppear,然后在viewDidLayout,最后viewDidAppear

- (void)viewDidLayoutSubviews{

    [super viewDidLayoutSubviews];

}

11.

(1. UIView(所有控件均继承它)有个contentMood属性,用来设置控件里面填充的文字/图片等的对齐方式(如:

默认UIViewContentModeScaleToFill,UIViewContentModeTop/Left/Right/TopLeft等),但一般只对UIImageView图片框有效,对Button等基本无效。

(2. 但是所有继承自UIControl的控件都有contentHorizontalAlignment和contentVerticalAlignment这2个属性,可以通过如下代码设置UIControl对象内容的水平和垂直对齐方式:

  btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//默认center

      btn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;//默认center

12.

在Storyboard或XIB中设置UILabel,UITextField,UITextView等文字时,如果想换行,按Opt +Enter或者Ctrl+Enter都可以。如果是在代码中设置的话,在需要换行的位置加入\n即可。如:@“adjh\n55655”

 

[BS] 小知识点总结

标签:

原文地址:http://www.cnblogs.com/stevenwuzheng/p/5422260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!