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

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

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)];returnattriString;

}

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 codeself.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];

}

}returnself;

}- (void)layoutSubviews{

[super layoutSubviews];if(!_curUser) {return;

}

self.titleLabel.text=@"头像";

[self.userIconView sd_setImageWithURL:[_curUser.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:kPlaceholderMonkeyRoundView(_userIconView)];

}+(CGFloat)cellHeight{return70.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];returncell;

}else{

TitleValueMoreCell*cell =[tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleValueMore forIndexPath:indexPath];

}returncell;

}

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];

}returnself;

}- (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];

}

其中几个值:#definekNavTitleFontSize 19#definekScreen_Width [UIScreen mainScreen].bounds.size.width#definekNavImageWidth (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:[BMCollectionCellclass] forCellWithReuseIdentifier:CELL_ID];

[self.view addSubview:_collectionView];

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

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航