IOS client Coding project record (2): ios client coding project

Source: Internet
Author: User

IOS client Coding project record (2): ios client coding project

9: third-party plug-ins

JSON object conversion: jsonModel registry.20.https://github.com/cewendel/swtableviewcellimg plug-in :mwphotobrowser ?### https://github.com/jdg/mbprogresshud

10: button display to set different fonts

[_ HeaderFansCountBtn setAttributedTitle: [self getStringWithTitle: @ "" andValue: _ curUser. fans_count.stringValue] forState: UIControlStateNormal]; Method (set different style display based on length):-(NSMutableAttributedString *) getStringWithTitle :( NSString *) title andValue :( NSString *) value {optional * 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], identifier: [UIColor colorWithHexString: @ "0x3bbd79"]} range: NSMakeRange (title. length + 1, value. length)]; return attriString ;}

11: accessoryType attribute of UITableviewcell

Cell. accessoryType = UITableViewCellAccessoryNone; // cell does not have any style cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator; // There is a small arrow on the right of the cell, which is a dozen pixels away from the right; cell. accessoryType = UITableViewCellAccessoryDetailDisclosureButton; // there is a blue circle button on the right of the cell; cell. accessoryType = UITableViewCellAccessoryCheckmark; // the right side of the cell is the right side of the cell;

12: layoutSubviews will be called in the following cases

A. Initialization of init will not trigger layoutSubviews. B. addSubview triggers layoutSubviews. C. Setting the view Frame triggers layoutSubviews. Of course, the premise is that the frame value has changed before and after it is set. D. Rolling a UIScrollView triggers layoutSubviews. E. Rotating Screen triggers the layoutSubviews event on the parent UIView. F. Changing the size of a UIView triggers the layoutSubviews event on the parent UIView. G. Call setLayoutSubviews directly.

13: buttons in the navigation bar (custom images)

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: custom table rows (inheriting UITableViewCell)

@ Interface trim () @ property (strong, nonatomic) UILabel * titleLabel; @ property (strong, nonatomic) UIImageView * userIconView; @ end @ implementation preview-(id) initWithStyle :( UITableViewCellStyle) style reuseIdentifier :( NSString *) reuseIdentifier {self = [super initWithStyle: style reuseIdentifier: reuseIdentifier]; if (self) {// Initialization code self. accessoryType = UITabl EViewCellAccessoryDisclosureIndicator; if (! _ TitleLabel) {_ titleLabel = [[UILabel alloc] initWithFrame: CGRectMake (plaintext, ([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-limit)-limit-30, ([TitleRImageMoreCell cellHeight]-limit)/2, limit, kTitleRImageMoreCell_HeightIcon)]; [_ userIconView doCircleFrame]; [self. contentView addSubview: _ userIconView] ;}} return self ;}- (void) layoutSub Views {[super layoutSubviews]; if (! _ CurUser) {return;} self. titleLabel. text = @ "Avatar"; [self. userIconView sd_setImageWithURL: [_ curUser. avatar labels: _ userIconView] placeholderImage: kPlaceholderMonkeyRoundView (_ userIconView)];} + (CGFloat) cellHeight {return 70.0;} @ end when calling (attribute values can be passed, and load different rows and Their heights in different places):-(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: blank]; return cell;} else {TitleValueMoreCell * cell = [tableView metadata: Rule forIndexPath: indexPath];} return cell ;}

15: when the direction of the button icon changes

[Self setImage: [UIImage imageNamed: @ "nav_arrow_down"] forState: UIControlStateNormal]; self. imageView. transform = CGAffineTransformRotate (self. imageView. transform, DEGREES_TO_RADIANS (180); // This is a 180 degree conversion, down or down

16: Add a control with image text in the middle of the navigation bar

-(UIDownMenuButton *) Updated :( 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. title List objectAtIndex: self. curIndex]; titleStr = menuObj. titleValue; CGFloat titleWidth = [titleStr getWidthWithFont: self. titleLabel. font constrainedToSize: CGSizeMake (kScreen_Width, 30)]; // obtain the text width CGFloat btnWidth = titleWidth + kNavImageWidth; self. frame = CGRectMake (kScreen_Width-btnWidth)/2, (44-30)/2, btnWidth, 30); self. titleEdgeInsets = UIEdgeInsetsMake (0,-kNavImageWidth, 0, kNavImageWidth); s Elf. imageEdgeInsets = upper (0, titleWidth, 0,-titleWidth); [self setTitle: titleStr forState: UIControlStateNormal]; [self setImage: [UIImage imageNamed: @ "lower"] forState: UIControlStateNormal];} several values: # define kNavTitleFontSize 19 # define kScreen_Width [UIScreen mainScreen]. bounds. size. width # define kNavImageWidth (15.0 + 5.0) is then directly assigned to titleview: UIDownMenuButton * navBtn = [[UIDownMenuBut Ton alloc] initWithTitles: titleList andDefaultIndex: index andVC: self]; navBtn. menuIndexChanged = block; self. navigationItem. titleView = navBtn; Note: All buttons have text and images, but the images are on the left. You must use uiedgeinsetsmake to change the position of the image and text. You can post on titleview in the navigation bar and put some other controls or views;

17: simple use of set view UICollectionView

The following three protocols must be followed: UICollectionViewDataSource, UICollectionViewDelegate, and layout. Cell Layout is set to UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setItemSize: CGSizeMake // set the cell size [flowLayout setScrollDirection: UICollectionViewScrollDirectionVertical]; // set the layout direction of flowLayout. sectionInset = UIEdgeInsetsMake (5, 5, 5, 5); // you can specify the number of cells in a row after setting the cell size, determined by the cell width, set the set view: _ 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]; Note: not all other delegate events are written, such as numberOfSectionsInCollectionView;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.