最近做项目遇到的一些小细节

UITableView自带分割线,如果想去掉,你只要
mTableView.separatorStyle = NO;

UITableView默认的点击某个cell,会变成蓝色并且失去焦点的时候不会恢复,你可以这么做,在cellForRowAtIndexPath中,加入如下代码

cell.selectionStyle = UITableViewCellSelectionStyleNone;//去选中状态

UITableViewCell的重用操作,几乎必用

static NSString *Cellidentifier = @"cell";
        cell = [tableView dequeueReusableCellWithIdentifier:Cellidentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cellidentifier];
        }


计算UILabel要显示一段文字所需要的大小

#pragma mark - 计算文字在某个fontSize所需要的占用的label的size
- (CGSize)getSizeWithText:(NSString *)text fontSize:(CGFloat)fontSize{
    
    UILabel *_lblDescText=[[UILabel alloc] init];
    UIFont* theFont = [UIFont systemFontOfSize:fontSize];
    [_lblDescText setFont:theFont];
    [_lblDescText setText:text];
    [_lblDescText sizeToFit];// 显示文本需要的长度和宽度
    
    CGSize size = CGSizeMake(_lblDescText.frame.size.width, _lblDescText.frame.size.height);
    return size;
}


当使用了UITab+UINav的组合,进去二级页面,想隐藏UITab,你可以在这样写

CookBookController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Storyboard_CookBook"];
    vc.hidesBottomBarWhenPushed = YES;//设置隐藏
    [self.navigationController pushViewController:vc animated:YES];

在android上用图片或者xml文件实现的圆角效果,IOS只需短短的2行代码,没错,真的就是2行

mainView.layer.cornerRadius = 5;/自己试着改变这个值,看看各个不同的效果。现在的设置是画了个圆圈。
        mainView.layer.masksToBounds = YES;

UILabel的字体加粗

_usernameLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:16];

ios自定义了返回按钮,手势返回失效,见此博客

http://weizhe.me/ios-7-back-gesture-sample/


集成下拉刷新,MJRefresh,号称一行代码搞定下拉刷新,github上有非常详细的教程,见此

https://github.com/CoderMJLee/MJRefresh#mjrefresh


Jastor 字典转对象,自己写好model,一切交给他吧

https://github.com/elado/jastor

github上有示例,以下是我自己用到的,首先,你定义的必须继承Jastor

.h

@interface RecommendObject : Jastor

@property (nonatomic,assign) BOOL update;
@property (nonatomic, strong) NSString *totalCount;
@property (nonatomic, strong) NSMutableArray *contentlist;//数组必须实现下面的方法
+(id)contentlist_class;//与contentlist相对应,后面加多——

@end
.m

@implementation RecommendObject

+(id)contentlist_class{
    return [RecommendCellBean class];
}
@end

RecommendCellBean.h

@interface RecommendCellBean : Jastor

@property (nonatomic, copy) NSString *contentID;
@property (nonatomic, copy) NSString *contentTitle;
@property (nonatomic, copy) NSString *createdDate;
@property (nonatomic, copy) NSString *imageThumnail;
@property (nonatomic, copy) NSString *contentThumnail;
@property (nonatomic, copy) NSString *supportCount;
@property (nonatomic, copy) NSString *fcount;
@property (nonatomic, copy) NSString *comment;

@end

数据如下:

{
    "contentlist": [
        {
            "ContentID": 108,
            "CreatedDate": "2015/4/7 13:21:30",
            "ContentThumnail": "fix content to be test!",
            "ImageThumnail": "http://b.hiphotos.baidu.com/image/pic/item/dc54564e9258d1096a795467d558ccbf6d814d49.jpg",
            "SupportCount": 1,
            "Fcount": 0,
            "Comment": 0
        },
        {
            "ContentID": 107,
            "CreatedDate": "2015/4/7 13:19:06",
            "ContentThumnail": "fix content to be test!",
            "ImageThumnail": "http://h.hiphotos.baidu.com/image/h%3D200/sign=5dd2c6a6312ac65c78056173cbf3b21d/2cf5e0fe9925bc313b351b5e5adf8db1ca13708f.jpg",
            "SupportCount": 0,
            "Fcount": 0,
            "Comment": 0
        }
    ],
    "update": true,
    "totalCount": 56
}

然后将以上数据放到字典nsdictionary里面,最后,只要执行如下代码

RecommendObject *object = [[RecommendObject alloc] initWithDictionary:dicData];

OK,搞定,数据已经成功变为我们的object了。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

corzfree

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值