Not a very advanced knowledge, just a few of the tips used in development. Keep up to date!
1, Uilabel according to the number of words to determine its frame
// define uilable width Max - ; // gets the size of the Uilabel, noting that the incoming font sizes remain the same as the Uilabel font size Cgsize contentsize = [Content Boundingrectwithsize:cgsizemake (CONTENTMAXW, maxfloat) options: Nsstringdrawinguseslinefragmentorigin attributes:@{nsfontattributename:[uifont systemFontOfSize: } context:nil].size; // Note To set the NumberOfLines property of the uilable to 0, you can display multiple lines of text 0;
2. Uilabel Display HTML code string
nsattributedstring * Attrstr == attrstr;
3. Using AFN to encapsulate the network layer
AFN is a very good HTTP network framework, generally in the project we will encapsulate the network layer on its basis. At this level, the incoming URLs and parameters, such as data encryption, are processed.
//YQHttpTool.h+ (void) Post: (NSString *) URLparams:(Nsdictionary *)paramsSuccess: (void(^) (IDJSON)) Success failure: (void(^) (Nserror *error)) Failure;+ (void)Get:(NSString *) URLparams:(Nsdictionary *)paramsSuccess: (void(^) (IDJSON)) Success failure: (void(^) (Nserror *error)) Failure; //YQHTTPTOOLS.M+ (void) Post: (NSString *) URLparams:(Nsdictionary *)paramsAuth: (Nsdictionary *) Auth success: (void(^) (ID)) Success Failure: (void(^) (Nserror *)) Failure{Afhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager manager];Mgr.responseserializer =[Afhttpresponseserializer serializer];[Mgr Post:url parameters:paramssuccess:^ (Afhttprequestoperation *operation,IDresponseobject) { if(Success) { success (responseobject); }} failure:^ (Afhttprequestoperation *operation, Nserror *error) { if(failure) { failure (error); } }];}
+ (void)Get:(NSString *) URLparams:(Nsdictionary *)paramsSuccess: (void(^) (ID)) Success Failure: (void(^) (Nserror *)) Failure{Afhttprequestoperationmanager *mgr =[Afhttprequestoperationmanager manager];Mgr.responseserializer =[Afhttpresponseserializer serializer];[Mgr Get:url parameters:params success:^ (afhttprequestoperation *operation,IDresponseobject) { if(Success) { success (responseobject); }} failure:^ (Afhttprequestoperation *operation, Nserror *error) { if(failure) { failure (error); } }];}4. Check for updates
//AppID for the application of AppID, it is recommended to define macroDefine AppID@"xxxxxxxxx"- (void) checkupdate{NSString*url = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@", AppID]; [Yqhttptool Getwithurl:urlparams: Nil success:^ (IDJSON) { IDJsonobject =[nsjsonserialization Jsonobjectwithdata:json options:nsjsonreadingallowfragments Error:nil]; if([Jsonobject Iskindofclass:[nsdictionaryclass]]) {nsdictionary*dic =Jsonobject; if(Nil! =dic) {Nsarray*result_array = [dic objectforkey:@"Results"]; if(Nil! = Result_array && [Result_array count]! =0) {nsdictionary*result_dic = [Result_array objectatindex:0]; if(Nil! =result_dic) {NSString*version = [Result_dic objectforkey:@"version"]; NSString*releasenotes = [Result_dic objectforkey:@"releasenotes"]; NSString*filepath = [[NSBundle mainbundle] Pathforresource:@"Info"OfType:@"plist"]; Nsmutabledictionary*dict =[Nsmutabledictionary Dictionarywithcontentsoffile:filepath]; NSString*oldversion = [Dict objectforkey:@"cfbundleshortversionstring"]; if([version compare:oldversion options:nsnumericsearch] = =nsordereddescending) {Uialertview*av = [[Uialertview alloc] Initwithtitle:@"Upgrade Tips"message:releasenotes Delegate: Self//delegate to self to execute the above callCancelbuttontitle:@"say it later ."Otherbuttontitles:@"Update Now", nil]; [AV show]; } }}}} failure:^ (Nserror *error) { }];}
Follow <UIAlertView>
-(void) Alertview: (Uialertview *) Alertview Diddismisswithbuttonindex: (Nsinteger) Buttonindex {
if (buttonindex! = [Alertview Cancelbuttonindex])
{
NSString *str = [NSString stringwithformat:@ "itms-apps://itunes.apple.com/app/id%@?mt=8", AppID];
Nsurl *url = [Nsurl urlwithstring:str];
[[UIApplication sharedapplication] openurl:url];
}
}
iOS Development Trivia