IOS UI Basic -10.0 QQ Chat layout keyboard and text usage

Source: Internet
Author: User

To achieve the effect:

Here are just a few of the knowledge points that are used

1. Picture contains text

When setting the text frame, use the size of the background (button), the text uses the inner margin

Background picture, using stretch

/* * *   return a picture that can be arbitrarily stretched without distortion * *  * * * + (UIImage *) Resizableimage: (NSString *) name{    * normal = [UIImage imagenamed:name];     0.5 ;     0.5 ;     return [Normal Resizableimagewithcapinsets:uiedgeinsetsmake (H, W, H, W)];}

When used:

   [Self.textview setbackgroundimage:[uiimage resizableimage:@ "chat_send_nor"] forstate: UIControlStateNormal];
2. Add whitespace to the input box

    //   Set the view Self.inputView.leftView to the left of the text box    = [[UIView alloc] Initwithframe:cgrectmake (0 0 8 0 )];     // Always show    Self.inputView.leftViewMode = uitextfieldviewmodealways;
3. Set the Send button to the keyboard of the input box

Set to send, and tick, as

Implement proxy Uitextfielddelegate, part of the code

@interfaceMjviewcontroller () <UITextFieldDelegate>@property (Weak, nonatomic) Iboutlet Uitextfield*Inputview;@end@implementationMjviewcontroller- (void) viewdidload{[Super Viewdidload]; //Set the text box proxySelf.inputview.Delegate=Self ;}#pragmaMark-text Box proxy/** * Click on the return button (the button in the bottom right corner of the keyboard) will call*/-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{//1. Send a message yourself[self addMessage:textField.text type:mjmessagetypeme]; //2. Automatically reply to a messageNSString *reply =[self replayWithText:textField.text];        [Self addmessage:reply type:mjmessagetypeother]; //3. Clear TextSelf.inputView.text =Nil; //return Yes    returnYES;}
4. Keyboard display and close

In Viewdidload, monitor the keyboard

    // 2. Notification    of keyboard monitoring object: nil];

Keyboardwillchangeframe method

/** * Call when the keyboard changes frame (position and size)*/- (void) Keyboardwillchangeframe: (Nsnotification *) note{//set the color of the windowSelf.view.window.backgroundColor =Self.tableView.backgroundColor; //0. Time to remove keyboard animationsCGFloat Duration =[Note.userinfo[uikeyboardanimationdurationuserinfokey] doublevalue]; //1. Get the last frame of the keyboardCGRect Keyboardframe =[Note.userinfo[uikeyboardframeenduserinfokey] cgrectvalue]; //2. Calculate the distance that the controller's view needs to be shiftedCGFloat transformy = KEYBOARDFRAME.ORIGIN.Y-Self.view.frame.size.height; //3. Performing animations[UIView animatewithduration:duration animations:^{self.view.transform= Cgaffinetransformmaketranslation (0, Transformy); }];}

Turn off the keyboard

/* * *   */-(void) scrollviewwillbegindragging: (Uiscrollview *)    scrollview{//  Exit keyboard     [Self.view endediting:yes];}

IOS UI Basic -10.0 QQ Chat layout keyboard and text usage

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.