常用代码片断,只为了便于记忆
日期格式转换
// 设置数据模型的时间 NSDate *now = [NSDate date]; NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"HH:mm"; msg.time = [fmt stringFromDate:now]; // fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss"; // 结果:2014-08-09 15:45:56
Modal
除了push之外,还有另外一种控制器的切换方式,那就是Modal
任何控制器都能通过Modal的形式展示出来
Modal的默认效果:新控制器从屏幕的最底部往上钻,直到盖住之前的控制器为止
// 以Modal的形式展示控制器 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion // 关闭当初Modal出来的控制器 - (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion;
@property属性的用法
- weak(assign) : 代理\UI控件
- strong(retain) : 其他对象(除代理\UI控件\字符串以外的对象)
- copy : 字符串
- assign : 非对象类型(基本数据类型int\float\BOOL\枚举\结构体)
图片开启交互
userInteractionEnabled属性默认值为YES,但UIView的一些子类中对该属性进行了覆盖,并将其默认值设置为了NO,其中UIImageView和UILabel就是这样的类。userInteractionEnabled属性在UIImageView和UILabel的文档中都有简单的描述。在实际的界面开发过程中,我们经常用UIImageView来模拟按钮或其它可以响应用户touch事件的显示区,并通过gesture来为其添加事件响应,因此为了保证事件能正常的接受,我们必须要显示的将UIImageView对象的userInteractionEnabled的值设为YES 。
UIImageView *containerView = [[UIImageView alloc] init]; containerView.image = [UIImage imageNamed:@"popover_background"]; containerView.userInteractionEnabled = YES; // 开启交互
图片固定宽高填充
// 内容模式 self.contentMode = UIViewContentModeScaleAspectFill; // 超出边框的内容都剪掉 self.clipsToBounds = YES;
获取扩展名
[photo.thumbnail_pic.lowercaseString hasSuffix:@"gif"];
点击cell的时候不要变色
self.backgroundColor = [UIColor clearColor]; // 点击cell的时候不要变色 self.selectionStyle = UITableViewCellSelectionStyleNone;
状态栏菊花
状态栏有网络请求前,设置为Yes 。在网络请求结束,设置为No。
//状态栏菊花 [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
修改pageController默认分页点
[_pageController setValue:[UIImage imageNamed:@"home_slipt_nor"] forKeyPath:@"_pageImage"]; [_pageController setValue:[UIImage imageNamed:@"home_slipt_pre"] forKeyPath:@"_currentPageImage"];