UIAlertController 弹框

一. 标准的Alert样式

//UIAlertController风格:UIAlertControllerStyleAlert
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"主标题" message:@"提示文字"preferredStyle:UIAlertControllerStyleAlert ];

//添加取消到UIAlertController中
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancelAction];

//添加确定到UIAlertController中
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:OKAction];

[self presentViewController:alertController animated:YES completion:nil]

UIWebView 实现长按保存图片功能

拿到需求之后分析了一下,其实主要功能点就是如何才能通过手指按压位置获取到相应的图片资源。

首先是给UiWebView加一个长按手势 :

UILongPressGestureRecognizer* longPressed = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
longPressed.delegate = self;
[self.webView addGestureRecognizer:longPressed];

YYModel字典转模型的几种详细用法

常用的几个方法

json转模型

+ (instancetype)yy_modelWithJSON:(id)json;

模型转字符串

- (NSString *)yy_modelToJSONString 

字典转模型

+ (instancetype)yy_modelWithDictionary:(NSDictionary *)dictionary ;

声明数组、字典或者集合里的元素类型时要重写

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass;

layoutSubviews 总结

ios layout机制相关方法

- (CGSize)sizeThatFits:(CGSize)size
- (void)sizeToFit
——————-
- (void)layoutSubviews
- (void)layoutIfNeeded
- (void)setNeedsLayout
——————–
- (void)setNeedsDisplay
- (void)drawRect

iOS特别知识点总结六

//判断内容是否全部为空格 yes 全部为空格 no 不是

- (BOOL)isEmpty:(NSString *) str {

    if (!str) {
        return true;
    } else {
        //A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).
        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];

        //Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
        NSString *trimedString = [str stringByTrimmingCharactersInSet:set];

        if ([trimedString length] == 0) {
            return true;
        } else {
            return false;
        }
    }
}

iOS开发之顶部状态栏statusBar颜色变化小结

iOS开发之顶部状态栏statusBar颜色变化小结

1.单个视图View没有导航控制器包装的情况下

(1.只设置启动状态栏颜色改变(白色),而视图中状态栏不变化(默认黑色),做如下的设置即可,两种方式不管先设置哪一个,另一个都会相应的变化

a. General 中的 Status Bar Style   -->  Light

b. plist 中增加 Status Bar Style   -->  UIStatusBarStyleLightContent

iOS开发之旅之懒加载

懒加载定义:延时加载,即当对象需要用到的时候再去加载。其实就是所谓的重写对象的get方法,当系统或者开发者调用对象的get方法时,再去加载对象。

需要注意:重写get方法时,先判断对象当前是否为空,为空的话再去实例化对象

- (NSArray *)shopData {

    if (!_shopData) {
        _shopData = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"shop" ofType:@"plist"]];
    }
    return _shopData;
}