知识点汇总(1)

总结的知识点

1.APP名字的更改

首先在info中找到Bundle name,改为自己的名字

2.APP图标的更改
在General中找到APPIcons and Launch Images更改APP icons source 将图标加到APPicon文件中需要将launch screen file 选项里面去掉,更改launch image source 将启动页图片加入Launchimage

3.UInavigationBar的appearance方法的使用

// 通过appearance统一设置所有UITabBarItem的文字属性

// 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通appearance对象来统一设置

NSMutableDictionary *attrs = [NSMutableDictionary dictionary];

    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];

    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];

    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];

    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];

    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];

    UITabBarItem *item = [UITabBarItem appearance];

    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];

    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];

4.UItarBarController初始化子控制器的封装
,需要继承自
UItarBarController


- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片

    vc.tabBarItem.title = title;

    vc.tabBarItem.image = [UIImage imageNamed:image];

    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];

    // 添加为子控制器

   // [self addChildViewController:vc];

   // 包装一个导航控制器
, 添加导航控制器为
tabbarcontroller的子控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}

5.自定义
TarBar控件的子视图的布局是在方法中实现的

- (void)layoutSubviews
{
  [super layoutSubviews];
 }

定制TarBar上自带的button的位置需要以下代码


- (void)layoutSubviews
{
   [super layoutSubviews];

    for (UIView *button in self.subviews) {

    //设置其他
UITabBarButton的frame不包括自定义的那个按钮

     if (![button isKindOfClass:NSClassFromString(@"UITabBarButton")]) continue;
    }
}

6.分类中属性的创建分类的创建source 找到objective-C File 选择category
在分类中声明@property, 只会生成方法的声明, 不会生成方法的实现和带有_下划线的成员变量需要自己创建setter方法和getter方法


#import <UIKit/UIKit.h>
@interface UIView (XMGExtension)

@property (nonatomic, assign) CGFloat width;

@property (nonatomic, assign) CGFloat height;

@property (nonatomic, assign) CGFloat x;

@property (nonatomic, assign) CGFloat y; 

#import "UIView+XMGExtension.h"

@implementation UIView (XMGExtension)

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}
- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;

    frame.size.height = height;

    self.frame = frame;

}
- (void)setX:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}
- (void)setY:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}
- (CGFloat)width
{
    return self.frame.size.width;
}
- (CGFloat)height
{
    return self.frame.size.height;
}
- (CGFloat)x
{
    return self.frame.origin.x;
}
- (CGFloat)y
{
   return self.frame.origin.y;
}

@end

分类中属性创建也可以用runtime实现


#import <UIKit/UIKit.h>

typedef void(^completionhandler)();

@interface UIControl (addBlock)

-(void)addActionforControlEvents:(UIControlEvents )controlEvent withcompletionhandler:(completionhandler)handler;
@end

#import "UIControl+addBlock.h"

#import <objc/runtime.h>

static void *blockKye=@"blockKye";

@implementation UIControl (addBlock)

-(void)addActionforControlEvents:(UIControlEvents )controlEvent withcompletionhandler:(completionhandler)handler{

    [self addTarget:self action:@selector(block) forControlEvents:controlEvent];

    void(^block)()=^{
        handler();
    };
    objc_setAssociatedObject(self, blockKye, block, OBJC_ASSOCIATION_COPY);

}
-(void)block{

    void (^block)()=objc_getAssociatedObject(self, blockKye);

    block();

}
@end

7.PCH文件的创建

新建一个pch,在other中找到PCH File
在build Settings 中找到prefix Header 修改文件路径

8.添加调试的日志输出宏添加到pch文件中


#ifdef DEBUG
//打印日志
#define AZLog(...) NSLog(__VA_ARGS__)

#else

#define AZLog(...)

#endif

//打印函数

#define AZLogFunc AZLog(@"%s", __func__)
#endif

9.UIBarButtonItem的封装 给他创建分类


#import <UIKit/UIKit.h>
@interface UIBarButtonItem (XMGExtension)

+ (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action;

@end

/////////////////////////////////////

#import "UIBarButtonItem+XMGExtension.h"
@implementation UIBarButtonItem (XMGExtension)

+ (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action

{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];

    [button setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];

    button.size = button.currentBackgroundImage.size;

    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

    return [[self alloc] initWithCustomView:button];

}

@end

设置导航栏左边的按钮


// 设置导航栏左边的按钮

    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"imageName" highImage:@"higeImageName" target:self action:@selector(yourClincked)];

10.颜色创建的宏 放在pch文件中


#define AZRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

11.通过继承
UINavigationController重写方法

/*- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

可以在这个方法中拦截所有push进来的控制器下面代码定制全局的返回键


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

{

    if (self.childViewControllers.count > 0) { // 如果
push进来的不是第一个控制器

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

        [button setTitle:@"返回
" forState:UIControlStateNormal];

        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];

        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];

        button.size = CGSizeMake(70, 30);
        // 让按钮内部的所有内容左对齐
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

//        [button sizeToFit];
        // 让按钮的内容往左边偏移
10
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);

        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];

        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

        // 隐藏
tabbarviewController.hidesBottomBarWhenPushed = YES;
    }
    // 这句
super的push要放在后面, viewController可以覆盖上面设置的leftBarButtonItem

    [super pushViewController:viewController animated:animated];

}
- (void)back
{
    [self popViewControllerAnimated:YES];
}
 

12.cell是否选中,选中后的回调方法,可以用于选中某个cell后cell的视图变化,比如选中某个cell的时候字体的颜色改变

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];    
    self.selectedIndicator.hidden = !selected;

    self.textLabel.textColor = selected ? self.selectedIndicator.backgroundColor : AZRGBColor(78, 78, 78);
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,585评论 4 365
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,923评论 1 301
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,314评论 0 248
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,346评论 0 214
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,718评论 3 291
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,828评论 1 223
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,020评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,758评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,486评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,722评论 2 251
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,196评论 1 262
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,546评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,211评论 3 240
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,132评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,916评论 0 200
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,904评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,758评论 2 274

推荐阅读更多精彩内容

  • Q.了解前后端分离吗(当时真不了解,但他细心地给我解释了一下,还建议我去看淘宝ued团队的文章) Q.用什么版本控...
    _Yfling阅读 457评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,105评论 18 139
  • 1.自定义控件 a.继承某个控件 b.重写initWithFrame方法可以设置一些它的属性 c.在layouts...
    圍繞的城阅读 3,022评论 2 4
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,037评论 29 470
  • 男子化妆术,自然需要一位有气质有爱心有胆量的男士,这样的男士大多很忙,所以聪明的我就去朋友圈盗照片去啦。 这么帅气...
    鬼鬼YDan阅读 276评论 0 1