IOS客户端Coding项目记录(二)
生活随笔
收集整理的這篇文章主要介紹了
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/mbprogresshud10: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 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];}}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等;?
總結
以上是生活随笔為你收集整理的IOS客户端Coding项目记录(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信浏览器内打开App Store链接
- 下一篇: 韩拓-七牛产品演进之路