/----------------------Functional Partitioning-----------------------------
To this step, you want to implement a custom TableCell to add a toolbar view with three lable (likes, comments, forwarded), so customize a view class
Custom Lyweibotoolbarview in xib right ribbon click on the first icon to remove the use AutoLayout Automatic layout point empty, and then in the size of the column to the distance above the lower edge of the view to constrain, Distance is 0. (Achieve toolbar following cell's height transform position, always on bottom edge)
Add a toolbar to the cell
Create a custom object through the Xib layout, using the following method to create
Lyweibotoolbarview *TV = [[[nsbundlemainbundle]loadnibnamed:@ "Lyweibotoolbarview" owner:self Options:nil] LastObject ];
Autoreseing layout, just implement the child control each initial position, here to set down 5 pixels
Tv.center = Cgpointmake (tv.center.x, tv.center.y+5);
Here to pass the Lyweibo data to the child control TV,TV to show the forwarding, comments, like the number, but the time of the Lyweibo data (the time is assigned Lyweibo in the controller) is in the following Setweibo method to get the
[Self.contentview ADDSUBVIEW:TV];
Set the color of the Contentview layer to white, distinguish the whole cell gray, split the effect
Self.contentView.backgroundColor = [Uicolor Whitecolor];
Self.backgroundcolor = [Uicolor Lightgraycolor];
Self.toolbarview = TV;
}
return self;
}
Overriding the set method of a property Weibo
-(void) Setweibo: (Lyweibo *) weibo{
_weibo = Weibo;
Self.nameLabel.text = Weibo.user.name;
Self.timeLabel.text = Weibo.created_at;
[Self.headiv SetImageWithURL:weibo.user.avatar_large];
Self.sourceLabel.text = Weibo.source;
Tell bar what data is displayed (forward ... )
Self.toolBarView.weibo = Weibo;
}
The control is displayed before it is called data ready to modify the custom control layout can be written in the secondary method
-(void) layoutsubviews{
[Super Layoutsubviews];
Let the Contentview height minus 10 to do the split line
Self.contentView.frame = CGRectMake (0, 0, self.bounds.size.width, self.bounds.size.height-10);
}
-(void) setselected: (BOOL) selected animated: (bool) Animated {
[Super setselected:selected animated:animated];
Configure The view for the selected state
}
}
----------------------Functional Partitioning-----------------------------
Get to the time format:
@ "Wed Feb 24 16:03:33 +0800 2016"
Day of the week: minute: seconds, time zone year
----------------------Functional Partitioning-----------------------------
Each time the micro-blog is refreshed, the display is based on the time sent, so it is not possible to override the Set method, you need to rewrite his get method
-(NSString *) created_at{
Get time to send Weibo
Turn the acquired string time into a timestamp
EEE (week) MMM (month) DD (days) HH hours mm minutes ss seconds Z time zone yyyy year
NSDateFormatter is a class of time to convert each other
NSDateFormatter *format = [[NSDateFormatter alloc]init];
Format the time to convert time to data in this format
Format.dateformat = @ "EEE MMM dd HH:mm:ss Z yyyy";
Set up a region
Format.locale = [[Nslocale alloc]initwithlocaleidentifier:@ "en_US"];
Convert time data to data
NSDate *weibodate = [format datefromstring:_created_at];
Get current time
NSDate *nowdate = [NSDate new];
Long nowtime = [Nowdate timeIntervalSince1970];
Long weibotime = [Weibodate timeIntervalSince1970];
Long time = Nowtime-weibotime;
if (time<60) {//a minute is shown in just
return @ "just";
}else if (time>60&&time<=3600) {
return [NSString stringwithformat:@ "%d minutes ago", (int) time/60];
}else if (time>3600&&time<3600*24) {
return [NSString stringwithformat:@ "%d hours ago", (int) time/3600];
}else{//Show Date directly
Convert Weibo data time to displayed time in mm month DD format
Format.dateformat = @ "mm month DD";
return [format stringfromdate:weibodate];
}
}
Lan Yi Messaging for iOS Weibo projects