IOS客户端Coding项目记录(二)

9:第三方插件整理

JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/
美化按键:BButton   https://github.com/mattlawer/BButton
状态栏提示:JDStatusBarNotification https://github.com/jaydee3/JDStatusBarNotification
照片显示插件:MJPhotoBrowser  https://github.com/azxfire/MJPhotoBrowser
在列表行划动显示更多选项:SWTableViewCell   https://github.com/cewendel/swtableviewcell
图片查看插件:mwphotobrowser   https://github.com/mwaterfall/mwphotobrowser
滚动条插件:asprogresspopupview  https://github.com/alskipp/asprogresspopupview
时间处理:nsdate-helper  https://github.com/billymeltdown/nsdate-helper
各种进度条:m13progresssuite https://github.com/marxon13/m13progresssuite
弹出提示mbprogresshud:  https://github.com/jdg/mbprogresshud

10:button显示设置不同字体

[_headerFansCountBtn setAttributedTitle:[self getStringWithTitle:@"粉丝" andValue:_curUser.fans_count.stringValue] forState:UIControlStateNormal];

方法(根据长度来设置其不同的样式显示):

- (NSMutableAttributedString*)getStringWithTitle:(NSString *)title andValue:(NSString *)value{
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", title, value]];
    [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],
                                 NSForegroundColorAttributeName : [UIColor blackColor]}
                         range:NSMakeRange(0, title.length)];
    
    [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],
                                 NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x3bbd79"]}
                         range:NSMakeRange(title.length+1, value.length)];
    return  attriString;
}

11:UITableviewcell的accessoryType属性

cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式  
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button; 
cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号; 

12:layoutSubviews在以下情况下会被调用

a、init初始化不会触发layoutSubviews。
b、addSubview会触发layoutSubviews。
c、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化。
d、滚动一个UIScrollView会触发layoutSubviews。
e、旋转Screen会触发父UIView上的layoutSubviews事件。
f、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件。
g、直接调用setLayoutSubviews。

13:导航栏的按键(自定义图片)

UIButton *settingBtn = [self navButtonWithImageName:@"settingBtn_Nav" action:@selector(settingBtnClicked:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];
    
    UIButton *addUserBtn = [self navButtonWithImageName:@"addUserBtn_Nav" action:@selector(addUserBtnClicked:)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addUserBtn];

14:自定义表格行(继承UITableViewCell)

@interface TitleRImageMoreCell ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UIImageView *userIconView;
@end
@implementation TitleRImageMoreCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        if (!_titleLabel) {
            _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([TitleRImageMoreCell cellHeight] -30)/2, 100, 30)];
            _titleLabel.backgroundColor = [UIColor clearColor];
            _titleLabel.font = [UIFont systemFontOfSize:16];
            _titleLabel.textColor = [UIColor blackColor];
            [self.contentView addSubview:_titleLabel];
        }
        if (!_userIconView) {
            _userIconView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreen_Width- kTitleRImageMoreCell_HeightIcon)- kPaddingLeftWidth- 30, ([TitleRImageMoreCell cellHeight] -kTitleRImageMoreCell_HeightIcon)/2, kTitleRImageMoreCell_HeightIcon, kTitleRImageMoreCell_HeightIcon)];
            [_userIconView doCircleFrame];
            [self.contentView addSubview:_userIconView];
        }
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    if (!_curUser) {
        return;
    }
    self.titleLabel.text = @"头像";
    [self.userIconView sd_setImageWithURL:[_curUser.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:kPlaceholderMonkeyRoundView(_userIconView)];
}

+ (CGFloat)cellHeight{
    return 70.0;
}

@end

然后进行调用时(可以属性传值,并在不同的地方加载不同的行及其高度):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        TitleRImageMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleRImageMore forIndexPath:indexPath];
        cell.curUser = _curUser;
        [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
        return cell;
}
else
{
TitleValueMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleValueMore forIndexPath:indexPath];
}
return cell;
}

15:当给按键的图标进行方向改变

[self setImage:[UIImage imageNamed:@"nav_arrow_down"] forState:UIControlStateNormal];
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS(180));//这这是进行180度转到,向下或向下

16:在导航栏中间增加一个带图片文字的控件

- (UIDownMenuButton *)initWithTitles:(NSArray *)titleList andDefaultIndex:(NSInteger)index andVC:(UIViewController *)viewcontroller{
    self = [super init];
    if (self) {
        _titleList = titleList;
        _curIndex = index;
        _curShowing = NO;
        _mySuperView = viewcontroller.view;
        
        self.backgroundColor = [UIColor clearColor];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [self.titleLabel setFont:[UIFont systemFontOfSize:kNavTitleFontSize]];
        [self.titleLabel setMinimumScaleFactor:0.5];
        [self addTarget:self action:@selector(changeShowing) forControlEvents:UIControlEventTouchUpInside];
        [self refreshSelfUI];
    }
    return self;
}

- (void)refreshSelfUI{
    NSString *titleStr = @"";
    DownMenuTitle *menuObj = [self.titleList objectAtIndex:self.curIndex];
    titleStr = menuObj.titleValue;
    CGFloat titleWidth = [titleStr getWidthWithFont:self.titleLabel.font constrainedToSize:CGSizeMake(kScreen_Width, 30)];//获得文字的宽度
    CGFloat btnWidth = titleWidth +kNavImageWidth;
    self.frame = CGRectMake((kScreen_Width-btnWidth)/2, (44-30)/2, btnWidth, 30);

    self.titleEdgeInsets = UIEdgeInsetsMake(0, -kNavImageWidth, 0, kNavImageWidth);
    self.imageEdgeInsets = UIEdgeInsetsMake(0, titleWidth, 0, -titleWidth);
    [self setTitle:titleStr forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:@"nav_arrow_down"] forState:UIControlStateNormal];
}

其中几个值:

#define  kNavTitleFontSize 19
#define kScreen_Width [UIScreen mainScreen].bounds.size.width
#define kNavImageWidth (15.0+5.0)

然后直接赋给titleview:

    UIDownMenuButton *navBtn = [[UIDownMenuButton alloc] initWithTitles:titleList andDefaultIndex:index andVC:self];
    navBtn.menuIndexChanged = block;
    self.navigationItem.titleView = navBtn;

注意:button都是有带文字跟图片的,只是图片都是在左边,要通过uiedgeinsetsmake对图片跟文字进行位置的改变。可以在导航栏的titleview做文章,放一些其它控件,或视图;

17:集合视图UICollectionView的简单使用

要遵循三个协议:UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout

设置单元格的布局
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setItemSize:CGSizeMake(70, 100)];//设置cell的尺寸
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);//设置其边界
//其布局很有意思,当你的cell设置大小后,一行多少个cell,由cell的宽度决定

然后设置集合视图:
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height) collectionViewLayout:flowLayout];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = [UIColor clearColor];
    [_collectionView registerClass:[BMCollectionCell class] forCellWithReuseIdentifier:CELL_ID];
    [self.view addSubview:_collectionView];

注意:其它委托事件没全写出,比如numberOfSectionsInCollectionView等;

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。