iOS Development Basics

Source: Internet
Author: User

http://blog.csdn.net/wokenshin/article/details/502922531, modify UI size 2, set color 3, prohibit horizontal screen 4, click on the blank space to hide the keyboard 5, pop up the keyboard, the following UI overall up 6, my tool class [macro definition etc] 1. The UI size can be modified by frame or bounds property, but the effect is different.
Frame
After modifying the size, the coordinates of the original upper-left corner are not changed, and the dimensions are changed by the original upper-left coordinate position unchanged.
Bounds
function is the same as frame, except that it is scaled in a midpoint position.

When modifying a position, the frame property is used, and its coordinate position represents the coordinate position of the parent space species.
2. Color setting:

+ (Uicolor *) colorwithred: (cgfloat) Redgreen: (cgfloat) Greenblue: (cgfloat) Bluealpha: (cgfloat) Alpha; specify HSB, Parameters are: Hue (hue), saturated (saturation), brightness (brightness)

+ (Uicolor *) Colorwithhue: (cgfloat) Huesaturation: (cgfloat) Saturationbrightness: (cgfloat) Brightnessalpha: (CGFloat ) Alpha;

Set the color of the mask when customizing the view you can do this, masks use a uiimageview to make Kenshin notes
Uicolor *color = [Uicolor Redcolor]; Uicolor *CL = [color colorwithalphacomponent:0.5f]; Custom 255 color values, turn 255 to 0-1
Cgfloatr  = (cgfloat) 225/255.0; CGFLOATG = (cgfloat) 66/255.0; CGFLOATB = (cgfloat) 88/255.0; CGFloat alpha = (cgfloat) 1.0;    Uicolor *mycolorrgb = [UIColorcolorWithRed:Rgreen:Gblue:Balpha:alpha  ];self.tableview.backgroundcolor = Mycolorrgb;

3.IOS No horizontal screen

4.
Hide the keyboard-click on the blank to hide, click Return to Hide

5.
When the keyboard appears, the subsequent view moves up the whole way
3.IOS No horizontal screen (two ways) can be tested by CMD + RIGHT ARROW key in simulator

1: Added in Appdelegate, this method can prohibit horizontal screen
-(Nsuinteger) Application: (UIApplication *) application Supportedinterfaceorientationsforwindow: (UIWindow *) window
{
return uiinterfaceorientationmaskportrait;
}



4. Hide the keyboard--click on the keyboard return to hide the keyboard, click on the blank space to hide the keyboard, click the keyboard return to hide the keyboard
2.1 Implement proxy <uitextfielddelegate>2.2 in the controller that needs to be implemented, Uitextfield where the function needs to be used, the delegate agent. Remember that it must be before instantiating "This step is important" 2.3 Implementing the Proxy Method-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField [TextField Resignfirstresponder];}
Click the blank space to hide the keyboard,
#pragma mark view Proxy click on the blank area is trigger-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{//off keyboard [Self.username    Resignfirstresponder]; [Self.password Resignfirstresponder];}
-(void) viewdidload{[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (keyboardWillAppear2:) Name: Uikeyboardwillshownotification Object:nil];[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (keyboardWillDisappear2:) Name: Uikeyboardwillhidenotification Object:nil];}
#pragma mark Keyboard Height calculation-(cgfloat) Keyboardendingframeheight: (nsdictionary *) userinfo//calculate the height of the keyboard {//Incoming (Nsdictionary *) UserInfo is used to store various information of the keyboard, in which the uikeyboardframeenduserinfokey corresponding to the size information of the keyboard, in cgrect form to remove CGRect    Keyboardendinguncorrectedframe = [[UserInfo objectforkey:uikeyboardframeenduserinfokey]cgrectvalue];    CGRect keyboardendingframe = [Self.view convertrect:keyboardendinguncorrectedframe fromView:nil]; return keyboardEndingFrame.size.height;} #pragma mark [Step 2/3] Scrolls the current view up the same height according to the keyboard height. -(void) KEYBOARDWILLAPPEAR2: (nsnotification *) notification{#pragma mark [step 3/3] When the keyboard disappears, the view needs to be restored to its original state. -(void) KEYBOARDWILLDISAPPEAR2: (nsnotification *) notification{cgrect currentframe = self.view.frame;    CGFloat Keyboardh = [self keyboardendingframeheight:[notification userInfo];    CURRENTFRAME.ORIGIN.Y = currentframe.origin.y + Keyboardh * 0.4;       Self.view.frame = Currentframe;        The following if statement principles and Keyboardwillappear if (CURRENTFRAME.ORIGIN.Y < 0) {currentframe.origin.y = 0;    Self.view.frame = Currentframe; }

}

6, my tool class [macro definition, etc.]

 tools.m// device//// created by Kenshin on 15-9-9.// copyright (c) 2015 Kenshin. All rights reserved.//#import <Foundation/Foundation.h> #import <sqlite3.h>//Get the wide, high # define of the phone screen screenwidth [[UIScreen mainscreen] Bounds].size.width#define screenheight [[UIScreen Mainscreen] bounds].size.height/ /FONT color is blue = = help page background color # bluemycolor [uicolor colorwithred:84.0/255 green:173.0/255 blue:235.0/255 alpha:1.0]# Define Colormybutton [Uicolor colorwithred:0.0/255 green:122.0/255 blue:255.0/255 alpha:1.0]//reference iOS default alert button Color # Define Colorpagein [Uicolor colorwithred:27.0/255 green:73.0/255 blue:97.0/255 alpha:1.0]//Deep # define COLORPAGECU [ Uicolor colorwithred:120.0/255 green:180.0/255 blue:215.0/255 alpha:1.0]//Light # define Colortextback [UIColor colorwithred:214.0/255 green:214.0/255 blue:214.0/255 alpha:1.0]//light grey//All buttons background # define imgbtnhighlighted [UIImage imagenamed:@ "buddy_header_bg_highlighted"]//ui a round of # define Yuanjiao 8//get status bar height seems to make 20#define statusheight [[UIApPlication sharedapplication] statusbarframe].size.height//switch Font size # define Switchfontsize [Uifont systemFontOfSize:14] #import "Tools.h" #import "sys/utsname.h" @implementation tools-(void) intofirtstvc{    Self.window = [[ UIWindow Alloc]initwithframe:[[uiscreen Mainscreen] bounds]];    Viewcontroller *rootController = [[ Viewcontroller alloc]init];    Self.window.rootViewController = rootcontroller;    Self.window.backgroundColor = [Uicolor whitecolor];    [Self.window makekeyandvisible];}

Get current phone model + (NSString *) getcurrentdevicemodel{    struct utsname systeminfo;    uname (& SystemInfo);    NSString *platform = [nsstring stringWithCString:systemInfo.machine encoding: nsutf8stringencoding];            if ([Platform isequaltostring:@ "iphone1,1" ] Return @ "iphone 2G (A1203)";    if ([Platform isequaltostring:@ "iphone1,2"]) return @ "iphone 3G (a1241/a1324) ";    if ([Platform isequaltostring:@" iphone2,1 "]) return @" IPhone 3GS (a1303/a1325) ";    if ([PLATFO RM isequaltostring:@ "iphone3,1"]) return @ "IPhone 4 (A1332)";    if ([Platform isequaltostring:@ "iphone3,2"]) return @ "iphone 4 (A1332)";    if ([Platform isequaltostring:@ "iphone3,3"]) return @ "iphone 4 (A1349)";  &N Bsp if ([Platform isequaltostring:@ "iphone4,1"]) return @ "IPhone 4S (a1387/a1431)";    if ([platform isequaltostring:@ "iphone5,1"]) return @ "IPhone 5 (A1428)";    If ([Platform isequaltostring:@ "iphone5,2"]) return @ "IPhone 5 (a1429/a1442)";    if ([Platform isequaltostring : @ "iphone5,3"]) return @ "IPhone 5c (a1456/a1532)";    if ([Platform isequaltostring:@ "iphone5,4"]) return @ " iphone 5c (a1507/a1516/a1526/a1529) ";    if ([Platform isequaltostring:@" iphone6,1 "]) return @" iphone 5s ( a1453/a1533) ";    if ([Platform isequaltostring:@" iphone6,2 "]) return @" IPhone 5s (a1457/a1518/a1528/a1530) " ;    if ([Platform isequaltostring:@ "iphone7,1"]) return @ "IPhone 6 Plus (a1522/a1524)";    if ([PLATF ORM isequaltostring:@ "iphone7,2"]) return @ "IPhone 6 (a1549/a1586)";    if ([Platform isequaltostring:@] iphone8,1 "]) return @" IPhone 6s Plus (a1522/a1524) ";    if ([Platform isequaltostring:@" iphone8,2 "]) return @" I Phone 6s (a1549/a1586) ";        if ([Platform isequaltostring:@" ipod1,1 "])   return @" IPod Touch 1G (A1213) ";    if ([Platform IsEqualtostring:@ "ipod2,1"])   return @ "IPod Touch 2G (A1288)";    if ([Platform isequaltostring:@ "ipod3,1"])   return @ "ipod Touch 3G (A1318)";    if ([Platform isequaltostring:@ "ipod4,1"])   return @ "ipod Touch 4G (A1367) ";    if ([Platform isequaltostring:@" ipod5,1 "])   return @" IPod Touch 5G (a1421/a1509) ";        if ([Platform isequaltostring:@ "ipad1,1"])   return @ "IPad 1G (a1219/a1337)";        if ([Platform isequaltostring:@ "ipad2,1"])   return @ "IPad 2 (A1395)";    if ([pl Atform isequaltostring:@ "ipad2,2"])   return @ "IPad 2 (A1396)";    if ([Platform isequaltostring:@ "IPad2, 3 "])   return @" ipad 2 (A1397) ";    if ([Platform isequaltostring:@" ipad2,4 "])   return @" ipad 2 (A139 5+new Chip) ";    if ([Platform isequaltostring:@" ipad2,5 "])   return @" IPad Mini 1G (A1432) ";    if ([Platform isequaltostring:@ "IPad2,6 "])   return @" IPad Mini 1G (A1454) ";    if ([Platform isequaltostring:@" ipad2,7 "])   return @" IP Ad Mini 1G (A1455) ";        if ([Platform isequaltostring:@" ipad3,1 "])   return @" IPad 3 (A1 416) ";    if ([Platform isequaltostring:@" ipad3,2 "])   return @" IPad 3 (A1403) ";    if ([platform isequaltostring:@ "ipad3,3"])   return @ "IPad 3 (A1430)";    if ([Platform isequaltostring:@ "ipad3,4"]) &N Bsp return @ "ipad 4 (A1458)";    if ([Platform isequaltostring:@ "ipad3,5"])   return @ "ipad 4 (A1459)";  & nbsp if ([Platform isequaltostring:@ "ipad3,6"])   return @ "IPad 4 (A1460)";        if ([platform isequaltostring:@ "ipad4,1"])   return @ "IPad Air (A1474)";    if ([Platform isequaltostring:@ "ipad4,2"])   return @ "ipad Air (A1475)";    if ([Platform isequaltostring:@ "ipad4,3"])   return @ "ipad Air (A1476 ) ";    if ([Platform isequaltostring:@ "ipad4,4"])   return @ "IPad Mini 2G (A1489)";    if ([Platform Isequaltostr ing:@ "ipad4,5"])   return @ "IPad Mini 2G (A1490)";    if ([Platform isequaltostring:@ "ipad4,6"])   RET Urn @ "IPad Mini 2G (A1491)";        if ([Platform isequaltostring:@ "i386"])     &NBSP;R Eturn @ "iphone Simulator";    if ([Platform isequaltostring:@ "x86_64"])    return @ "iphone Simulator ";    return platform;} @end

iOS Development Basics

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.