tips

修改返回按钮:

UIImage *backImage = [UIImageimageNamed:@"navback"];     [[UIBarButtonItemappearance]setBackButtonBackgroundImage:[backImageresizableImageWithCapInsets:UIEdgeInsetsMake(0, backImage.size.width,0,0)]                                                      forState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];     [[UIBarButtonItemappearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(-233,0)forBarMetrics:UIBarMetricsDefault];

tableview快速创建:

#pragma mark-tableview delegate


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return80;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return0;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return0;

}

#pragma mark-datasource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return10;

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return1;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell* cell=[[UITableViewCellalloc]init];

    return cell;

}

uicollectiobview

 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayoutalloc]init];

    layout.itemSize             =CGSizeMake(myscreenwith/8.0,64);

    layout.footerReferenceSize  =CGSizeMake(0,0);

    

    layout.sectionInset            =UIEdgeInsetsMake(0,0,0,0);

    layout.minimumInteritemSpacing =0.0;

    layout.minimumLineSpacing      =0.0;

    _week=[[UICollectionViewalloc]initWithFrame:CGRectMake(0,0,320,568)collectionViewLayout:layout];

#pragma mark -- UICollectionViewDataSource

//定义展示的UICollectionViewCell的个数

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

    return30;

}

//定义展示的Section的个数

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

    return1;

}

//每个UICollectionView展示的内容

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

    staticNSString * CellIdentifier =@"GradientCell";

    UICollectionViewCell * cell = [collectionViewdequeueReusableCellWithReuseIdentifier:CellIdentifierforIndexPath:indexPath];

    

    cell.backgroundColor = [UIColorcolorWithRed:((10 * indexPath.row) /255.0)green:((20 * indexPath.row)/255.0)blue:((30 * indexPath.row)/255.0)alpha:1.0f];

    return cell;

}

#pragma mark --UICollectionViewDelegateFlowLayout

//定义每个UICollectionView的大小

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{

    returnCGSizeMake(96,100);

}

//定义每个UICollectionView margin

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section

{

    returnUIEdgeInsetsMake(5,5,5,5);

}

#pragma mark --UICollectionViewDelegate

//UICollectionView被选中时调用的方法

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{

    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionViewcellForItemAtIndexPath:indexPath];

    cell.backgroundColor = [UIColorwhiteColor];

}

//返回这个UICollectionView是否可以被选择

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath

{

    returnYES;

滑动事件:

//滑动开始事件

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touchesanyObject];

    CGPoint pointone = [touchlocationInView:self.view];//获得初始的接触点

    startPoint  = pointone;

}

//滑动移动事件

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touchesanyObject];

    //imgViewTop是滑动后最后接触的View

    CGPoint pointtwo = [touchlocationInView:self.view]; //获得滑动后最后接触屏幕的点

    

    if(fabs(pointtwo.x-startPoint.x)>100)

    {  //判断两点间的距离

        bMove =YES;

    }

}

//滑动结束处理事件

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touchesanyObject];

    pointtwo = [touchlocationInView:self.view]; //获得滑动后最后接触屏幕的点

    if((fabs(pointtwo.x-startPoint.x)>20)&&(bMove))

    {

        //判断点的位置关系左滑动

        if(pointtwo.x-startPoint.x<0)

        {   //左滑动业务处理

            NSLog(@"左滑、、、、、");

        }

        //判断点的位置关系右滑动

        else

        {  //右滑动业务处理

            NSLog(@"右滑、、、、、");

        }

    }

}


hitest:

//-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

//    CGPoint point1=[_container convertPoint:point fromView:self];

//    //    if ([_container pointInside:point1 withEvent:event]) {

//    //        return nil;

//    //    }

//    return _edit;

//}



 //统一修改导航栏字体

    [[UINavigationBarappearance]setTitleTextAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:17],

                                                         NSForegroundColorAttributeName:[UIColorcolorWithRed:51/255.0green:51/255.0 blue:51/255.0 alpha:1.0]}];

    

    //修改系统返回键按钮样式

    UIImage *backImage = [UIImageimageNamed:@"navback"];     [[UIBarButtonItemappearance]setBackButtonBackgroundImage:[backImageresizableImageWithCapInsets:UIEdgeInsetsMake(0, backImage.size.width,0,0)]                                                      forState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];     [[UIBarButtonItemappearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(-233,0)forBarMetrics:UIBarMetricsDefault];

    [[UIBarButtonItemappearance]setTitleTextAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:15]}forState:UIControlStateNormal];

修改导航栏与状态栏颜色

 self.navigationController.navigationBar.barTintColor =[UIColor colorWithRed:24/255.0green:179/255.0blue:139.0/255.0alpha:1.0];

How Do I Declare A Block in Objective-C?

As a local variable:

returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};

As a property:

@property (nonatomic, copy) returnType (^blockName)(parameterTypes);

As a method parameter:

- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;

As an argument to a method call:

[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];

As a typedef:

typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
This site is not intended to be an exhaustive list of all possible uses of blocks.
If you find yourself needing syntax not listed here, it is likely that a  typedef would make your code more readable.

iOS8开发中采用xcassets设置LaunchImage后如何获取自适应屏幕大小的启动图片



导航栏去掉下面的黑线

if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
        NSArray *list=self.navigationController.navigationBar.subviews;
        for (id obj in list) {
            if ([obj isKindOfClass:[UIImageView class]]) {
                UIImageView *imageView=(UIImageView *)obj;
                NSArray *list2=imageView.subviews;
                for (id obj2 in list2) {
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView2=(UIImageView *)obj2;
                        imageView2.hidden=YES;
                    }
                }
            }
        }
    }


git commands

  • 是否每次敲block都要在心里默念: 没有返回值~括号~尖号~参数...不用这么麻烦, 试着敲个inline,还没等你敲完,人家xcode已经给你提示了,
    喏:


    然后你负责敲个回车:


    哈哈哈,这需要记?

  • 把block去typedef也是一样的.直接敲typedef...选择typedefBlock那一项:


一个回车之后请做填空题:


  • 写枚举的时候总是不小心写个#号或者@,又或者不小心忘了应该先写typedef还是enum, 不要担心, 从此你只需要敲enumdef,如:

回车之后就是见证奇迹的时刻:


  • 使用GCD定时器的时候,输入dispatch_source后查找Xcode内置代码段

GCD定时器使用的快捷输入

Xcode会帮你做好GCD定时器一系列的创建、设置属性、回调函数、启动等工作.意外收获的惊喜呀,所以赶紧补上来了.


GCD定时器快捷创建

拖动tableView时收起键盘

只有一行代码:

tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

其中keyboardDismissMode是UIScrollView的属性,
它的值除了UIScrollViewKeyboardDismissModeNone,
还有一种是UIScrollViewKeyboardDismissModeInteractive,表示键盘可以随着手指下滑而移出屏幕,具体效果小伙伴们可以自己试着体验下.

既然是UIScrollView的属性,那么在文字常用的UITextView等控件中也可以使用.

我们可以通过Quartz 2D来绘制文本内容
绘制文本内容
//绘图只能在当前位方法中调用,否则无法得到图形上下文
- (void)drawRect:(CGRect)rect{

    //要显示的文字
    NSString *str = @"苹果在昨天成功获得一项关于音频方面的专利,可以让纤薄电子设备中的扬声器音量更高,音质更好。虽然该专利的文件内容冗长,不过却描述了一种方法:“由于便携式电子设备的体积限制,在使设备更薄更小的同时,提供高质量的音频输出/接收能力已变得愈发困难。因此,就需要新的方法,来提供高质量的音频输出/接收能力。” ";

    //绘制文字显示的指定区域
    CGRect rect = CGRectMake(20, 50, 374, 500);
    //字体大小
    UIFont *font = [UIFont systemFontOfSize:25];
    //字体颜色
    UIColor *color = [UIColor redColor];
    //初始化段落样式
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    //居中对齐
    NSTextAlignment textAlignment = NSTextAlignmentCenter;
    //设置段落样式
    paragraphStyle.alignment = textAlignment;

    [str drawInRect:rect withAttributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:color, NSParagraphStyleAttributeName:paragraphStyle}];

}
绘制图像
//绘图只能在当前位方法中调用,否则无法得到图形上下文
- (void)drawRect:(CGRect)rect{

    //加载图片
    UIImage *image = [UIImage imageNamed:@"mv1.jpg"];

    //拉伸的方式显示图片
    [image drawInRect:CGRectMake(20, 300, 374, 400)];
    //设置图片位置(平铺的方式显示图片)
    //[image drawAsPatternInRect:CGRectMake(20, 400, 374, 336)];

}
同样我们可以通过Quartz 2D进行图片剪切
//绘图只能在当前位方法中调用,否则无法得到图形上下文
- (void)drawRect:(CGRect)rect{

    //获取图形上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    //指定上下文显示的范围
    CGContextAddEllipseInRect(context, CGRectMake(80, 50, 100, 100));
    //裁剪
    CGContextClip(context);

    //获取图片
    UIImage *image = [UIImage imageNamed:@"mv2.jpg"];
    //
    [image drawAtPoint:CGPointMake(50, 50)];

}

coretext里面设置富文本:

NSString*string =@"Be Bold! And a little color wouldn’t hurt either.";NSDictionary*attrs = @{NSFontAttributeName: [UIFontsystemFontOfSize:36]};

NSMutableAttributedString*
as = [[
NSMutableAttributedStringalloc]initWithString:stringattributes:attrs];

[as addAttribute:NSFontAttributeNamevalue:[UIFontboldSystemFontOfSize:36]

range:[stringrangeOfString:@"Bold!"]];

[as addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor]

range:[stringrangeOfString:@"little color"]];

[as addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:18]

range:[stringrangeOfString:@"little"]];self.label.attributedText= as; 


NSMutableAttributedString*as = ...

[as enumerateAttribute:...inRange:...options:...

{
...

}]; 

CGContextMoveToPoint设置起点
CGContextClosePath 连接起点和当前点
CGPathCreateMutable 类似于 CGContextBeginPath
CGPathMoveToPoint 类似于 CGContextMoveToPoint
CGPathAddLineToPoint 类似于 CGContextAddLineToPoint
CGPathAddCurveToPoint 类似于 CGContextAddCurveToPoint
CGPathAddEllipseInRect 类似于 CGContextAddEllipseInRect
CGPathAddArc 类似于 CGContextAddArc
CGPathAddRect 类似于 CGContextAddRect
CGPathCloseSubpath 类似于 CGContextClosePath
CGContextAddPath函数把一个路径添加到graphics


 dispatch_group_t group = dispatch_group_create();

    dispatch_group_enter(group);

    [RecipeInfo fetchRecipeWithCompletionBlock:^(id returnValue) {

        info = [RecipeInfo yy_modelWithDictionary:returnValue];

        dispatch_group_leave(group);

    } WithFailureBlock:^(NSError *error) {

        dispatch_group_leave(group);

    }];

    

    dispatch_group_enter(group);

    [HomePageNavContent fetchNavContentWithCompletionBlock:^(id returnValue) {

        navContent = [HomePageNavContent yy_modelWithDictionary:returnValue];

        dispatch_group_leave(group);

    } WithFailureBlock:^(NSError *error) {

        dispatch_group_leave(group);

    }];

    dispatch_group_notify(group, dispatch_get_main_queue(), ^{

        [self.tableView reloadData];

    });

1. 网络图片显示大体步骤:

  1. 下载图片
  2. 图片处理(裁剪,边框等)
  3. 写入磁盘
  4. 从磁盘读取数据到内核缓冲区
  5. 从内核缓冲区复制到用户空间(内存级别拷贝)
  6. 解压缩为位图(耗cpu较高)
  7. 如果位图数据不是字节对齐的,CoreAnimationcopy一份位图数据并进行字节对齐
  8. CoreAnimation渲染解压缩过的位图

以上4,5,6,7,8步是在UIImageViewsetImage时进行的,所以默认在主线程进行(iOS UI操作必须在主线程执行)。

2. 一些优化思路:

  • 异步下载图片
  • image解压缩放到子线程
  • 使用缓存 (包括内存级别和磁盘级别)
  • 存储解压缩后的图片,避免下次从磁盘加载的时候再次解压缩
  • 减少内存级别的拷贝 (针对第5点和第7点)
  • 良好的接口(比如SDWebImage使用category
  • Core Data vs 文件存储
  • 图片预下载

有时候使用UITableView所实现的列表,会使用到section,但是又不希望它粘在最顶上而是跟随滚动而消失或者出现,下面的代码片段就是实现此功能:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值