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