iOS notes 4

Source: Internet
Author: User

1. How to calculate the text size

1  Nsdictionary *dict = @{nsfontattributename:njtextfont}; 2     Cgsize maxSize = Cgsizemake (maxfloat); 3     Cgsize textSize = [_message.text boundingrectwithsize:maxsize Options:nsstringdrawinguseslinefragmentorigin Attributes:dict context:nil].size; 4 5     Cgsize maxSize = Cgsizemake (maxfloat); 6     Cgsize textSize = [self sizewithstring:_message.text font:njtextfont maxsize:maxsize];

2. Set button to complete background picture

1. Set the inner margin of the button

2. In the button text size plus the padding

3. Stretch the picture using the Resizeableimage method

1   Load existing image 2     UIImage *norimage = [UIImage imagenamed:imagename]; 3      get half of the width of the original picture 4     0.5 ; 5     0.5 ; 6      generates a picture that stretches the specified position 7     UIImage *newimage = [Norimage Resizableimagewithcapinsets:uiedgeinsetsmake (H, W, H, W) Resizingmode: Uiimageresizingmodestretch];

Usage of 3.NSDate

1 //implementing the current time as the sending time2NSDate *date = [NSDate Date];//Create a Time object3 //NSLog (@ "%@", date);4     //time can be converted to a string5     //You can also convert a string to a time6     //2014-05-317     //2014/05/318     //05/31/20149NSDateFormatter *formatter =[[NSDateFormatter alloc] init];Ten     //HH stands for 24 hours hh for 12 hours OneFormatter.dateformat =@"hh:mm"; ANSString *time =[Formatter stringfromdate:date]; -      -NSLog (@"Time =%@", time); theMessage.time = time;

4. Monitor keyboard notification settings keyboard and view change location

1 [[Nsnotificationcenter  Defaultcenter] addobserver:self selector: @selector (keyboardwillchange:) Name:uikeyboardwillchangeframenotification  Object: nil];
1 /*2 UserInfo = {3 //keyboard pop-up rhythm4 Uikeyboardanimationcurveuserinfokey = 7;5 //keyboard pop-up time to perform animation6 Uikeyboardanimationdurationuserinfokey = "0.25"; Uikeyboardboundsuserinfokey = "Nsrect: {{0, 0}, {216}}";7 Uikeyboardcenterbeginuserinfokey = "Nspoint: {588}";8 Uikeyboardcenterenduserinfokey = "Nspoint: {372}";9 uikeyboardframechangedbyuserinteraction = 0;Ten Uikeyboardframebeginuserinfokey = "Nsrect: {{0, 480}, {* *, 216}}"; One       A //keyboard pop-up frame - Uikeyboardframeenduserinfokey = "Nsrect: {{0, * * *}, {216}}"; -       the //The frame when the keyboard is hidden - Uikeyboardframeenduserinfokey = "Nsrect: {{0, 480}, {* *, 216}}"; -      }} -  +      */ -NSLog (@"Keyboard Popup%@", notification); +      A     /* at calculate the distance that needs to be moved - The value to move when it pops up = the Y value of the keyboard-controls the height of the view = distance to move - -480 = -216 -       - The value to move when hidden = the Y value of the keyboard-controls the height of the view = distance to move - 480-480 = 0 in     */

Change the view position without adding animations, the system has been implemented

5. Scroll the TableView to the last line

    // 2. Refresh the table     [Self.tableview reloaddata];         // 3. Let Tableveiw scroll to the last line    Nsindexpath *path = [Nsindexpath indexPathForRow:self.messages.count-1 insection:0];        / *     Atindexpath: Which line to scroll to     atscrollposition: Where to scroll to     animated: whether scrolling animation is required      */     [Self.tableview scrolltorowatindexpath:path atscrollposition:uitableviewscrollpositionbottom Animated: YES];

iOS notes 4

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.