码迷,mamicode.com
首页 > 移动开发 > 详细

IOS开发基础

时间:2016-04-27 12:21:39      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

1、修改UI大小
2、设置颜色
3、禁止横屏
4、点击空白处隐藏键盘
5、弹出键盘时,后面的UI整体上移
6、我的工具类[宏定义等]
1、修改UI大小可以通过frame或bounds属性来实现,但二者效果不同。

frame:

     修改大小后,原先的左上角的坐标不会改变,既以原来的左上角坐标位置保持不变为前提进行尺寸的改变。

bounds

      功能同frame,不同之处在于,以一身中点位置进行缩放。


修改位置的时候使用frame属性,它的坐标位置表示是的是一身在父空间种的坐标位置。

2、颜色设置:

+ (UIColor *)colorWithRed:(CGFloat)redgreen:(CGFloat)greenblue:(CGFloat)bluealpha:(CGFloat)alpha; 指定HSB,参数是:色调(hue),饱和的(saturation),亮度(brightness)

+ (UIColor *)colorWithHue:(CGFloat)huesaturation:(CGFloat)saturationbrightness:(CGFloat)brightnessalpha:(CGFloat)alpha;

在自定义View的时候 设置蒙版的颜色可以这样弄,蒙版用一个UIImageView来做 kenshin笔记
UIColor *color = [UIColor redColor]; UIColor *cl = [color colorWithAlphaComponent:0.5f]; 自定义255的颜色值,将255转成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禁止横屏

4.
对键盘的隐藏——点击空白处隐藏、点击return键隐藏

5.
键盘出现时,后面的视图整体上移的方法
3.IOS禁止横屏(两种方式) 可以通过 cmd +右 方向键 在模拟器中测试

1:在AppDelegate中增加,这个方法可以禁止横屏

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  
    {  
         return UIInterfaceOrientationMaskPortrait;  
    }



4.对键盘的隐藏——点击键盘return键隐藏键盘、点击空白处隐藏键盘、
点击键盘return键隐藏键盘
2.1在需要实现的控制器中实现代理<UITextFieldDelegate>
2.2需要使用该功能的UITextField处,委托代理。记住一定是要在实例化之前【这一步很重要】
2.3实现代理方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
    [textField resignFirstResponder];
}

点击空白处隐藏键盘、
#pragma mark view代理 点击空白区域是触发
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //关闭键盘
    [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 键盘 高度的计算
-(CGFloat)keyboardEndingFrameHeight:(NSDictionary *)userInfo//计算键盘的高度
{
//    传入的(NSDictionary *)userInfo用于存放键盘的各种信息,其中UIKeyboardFrameEndUserInfoKey对应的存放键盘的尺寸信息,以CGRect形式取出
    CGRect keyboardEndingUncorrectedFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
    CGRect keyboardEndingFrame = [self.view convertRect:keyboardEndingUncorrectedFrame fromView:nil];
    return keyboardEndingFrame.size.height;
}
#pragma mark [步骤2/3]根据键盘高度将当前视图向上滚动同样高度。
-(void)keyboardWillAppear2:(NSNotification *)notification
{
   #pragma mark [步骤3/3]当键盘消失后,视图需要恢复原状。
-(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;
   
    //下面if语句的原理和keyboardWillAppear
    if (currentFrame.origin.y < 0)
    {
        currentFrame.origin.y = 0;
        self.view.frame = currentFrame;
    }

}

 

6、我的工具类[宏定义等]

// //  Tools.m //  Device // //  Created by kenshin on 15-9-9. //  Copyright (c) 2015年 kenshin. All rights reserved. // #import <Foundation/Foundation.h> #import <sqlite3.h> //获取手机屏幕的宽、高 #define screenWidth [[UIScreen mainScreen] bounds].size.width #define screenHeight [[UIScreen mainScreen] bounds].size.height //字体颜色 为蓝色==帮助页面的背景色 #define 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]//参照IOS默认的Alert按钮颜色 #define colorPageIn [UIColor colorWithRed:27.0/255 green:73.0/255 blue:97.0/255 alpha:1.0]//深 #define colorPageCu [UIColor colorWithRed:120.0/255 green:180.0/255 blue:215.0/255 alpha:1.0]//浅 #define colorTextBack [UIColor colorWithRed:214.0/255 green:214.0/255 blue:214.0/255 alpha:1.0]//浅灰色 //全部按钮的背景 #define imgBtnHighlighted [UIImage imageNamed:@"buddy_header_bg_highlighted"] //UI的圆角 #define YUANJIAO 8 //获取状态栏高度 貌似都使20 #define statusHeight [[UIApplication sharedApplication] statusBarFrame].size.height //开关 字体大小 #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]; }

//获取当前手机型号 + (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 ([platform 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)";     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 ([platform 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 @"iPhone 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 ([platform isEqualToString:@"iPad2,2"])   return @"iPad 2 (A1396)";     if ([platform isEqualToString:@"iPad2,3"])   return @"iPad 2 (A1397)";     if ([platform isEqualToString:@"iPad2,4"])   return @"iPad 2 (A1395+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 @"iPad Mini 1G (A1455)";          if ([platform isEqualToString:@"iPad3,1"])   return @"iPad 3 (A1416)";     if ([platform isEqualToString:@"iPad3,2"])   return @"iPad 3 (A1403)";     if ([platform isEqualToString:@"iPad3,3"])   return @"iPad 3 (A1430)";     if ([platform isEqualToString:@"iPad3,4"])   return @"iPad 4 (A1458)";     if ([platform isEqualToString:@"iPad3,5"])   return @"iPad 4 (A1459)";     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 isEqualToString:@"iPad4,5"])   return @"iPad Mini 2G (A1490)";     if ([platform isEqualToString:@"iPad4,6"])   return @"iPad Mini 2G (A1491)";          if ([platform isEqualToString:@"i386"])      return @"iPhone Simulator";     if ([platform isEqualToString:@"x86_64"])    return @"iPhone Simulator";     return platform; } @end

IOS开发基础

标签:

原文地址:http://www.cnblogs.com/wanghuaijun/p/5438017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!