iOS 第四天之ViewController

来源:互联网 发布:vb savepicture jpg 编辑:程序博客网 时间:2024/04/27 22:39

简单记载下今天学的基础

//  ViewController.m#import "ViewController.h"@interface ViewController ()@property (nonatomic, strong) UITextField * textField;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    UITextField * textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, self.view.frame.size.width - 40, 60)];    /*     设置边框样式     typedef NS_ENUM(NSInteger, UITextBorderStyle) {     UITextBorderStyleNone,     // 什么都没有(默认)     UITextBorderStyleLine,     // 周围加黑色线条     UITextBorderStyleBezel,    // 周围加灰色线条,上、左加阴影     UITextBorderStyleRoundedRect  // 带圆角四周加灰色线条     };     textFeld.borderStyle = UITextBorderStyleRoundedRect;     */    textField.borderStyle = UITextBorderStyleRoundedRect;//    textField.text = @"请输入密码";    //设置提示文字    textField.placeholder = @"请输入密码";    //设置输入文字的颜色    textField.textColor = [UIColor redColor];    //开始编辑是否清除文本//    textField.clearsOnBeginEditing = YES;//    textField.textAlignment = NSTextAlignmentCenter;    //设置字体    textField.font = [UIFont systemFontOfSize:50];    //字体适应宽度//    textField.adjustsFontSizeToFitWidth = YES;    //设置最小字体//    textField.minimumFontSize = 1;    //设置删除按钮的出现时间//    textField.clearButtonMode = UITextFieldViewModeWhileEditing;    //设置textField的左视图    UIView * small = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];    small.backgroundColor = [UIColor grayColor];    textField.leftView = small;    textField.leftViewMode = UITextFieldViewModeAlways;    //设置安全密码//    textField.secureTextEntry = YES;    /*     设置键盘的样式     typedef NS_ENUM(NSInteger, UIKeyboardType) {     UIKeyboardTypeDefault,  默认键盘,支持所有字符      UIKeyboardTypeASCIICapable,支持ASCII的默认键盘   UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符     UIKeyboardTypeURL,URL , 键盘,支持.com按钮 只支持URL字符    UIKeyboardTypeNumberPad,    数字键盘     UIKeyboardTypePhonePad,      电话键盘     UIKeyboardTypeNamePhonePad,   电话键盘,也支持输入人名     UIKeyboardTypeEmailAddress,    用于输入电子 邮件地址的键盘     UIKeyboardTypeDecimalPad   数字键盘 有数字和小数点    UIKeyboardTypeTwitter 优化的键盘,方便输入@、#字符     };     */    textField.keyboardType = UIKeyboardTypeEmailAddress;    /*     return键变成什么键     typedef NS_ENUM(NSInteger, UIReturnKeyType) {     UIReturnKeyDefault, //默认 灰色按钮,标有Return     UIReturnKeyGo,  //标有Go的蓝色按钮     UIReturnKeyGoogle, //标有Google的蓝色按钮,用语搜索     UIReturnKeyJoin, //标有Join的蓝色按钮     UIReturnKeyNext, //标有Next的蓝色按钮     UIReturnKeyRoute,  //标有Route的蓝色按钮     UIReturnKeySearch, //标有Search的蓝色按钮     UIReturnKeySend, //标有Send的蓝色按钮     UIReturnKeyYahoo, //标有Yahoo的蓝色按钮     UIReturnKeyDone,  //标有Done的蓝色按钮     UIReturnKeyEmergencyCall, //紧急呼叫按钮     };     */    textField.returnKeyType = UIReturnKeyGo;    /*     输入字母大小写     typedef NS_ENUM(NSInteger, UITextAutocapitalizationType) {     UITextAutocapitalizationTypeNone, // 不自动大写 (默认)     UITextAutocapitalizationTypeWords, // 单词首字母大写     UITextAutocapitalizationTypeSentences, // 句子的首字母大写     UITextAutocapitalizationTypeAllCharacters, // 所有字母都大写     };     textFeld.autocapitalizationType = UITextAutocapitalizationTypeNone;     */    textField.autocapitalizationType = UITextAutocapitalizationTypeWords;    self.textField = textField;    [self.view addSubview:textField];}

顺便记载下 经过封装的九宫格

////  CustomButton.h//  九宫格//#import <UIKit/UIKit.h>@interface CustomButton : UIButton@end//reserved.//#import "CustomButton.h"static const CGFloat kScale = 0.7;@implementation CustomButton- (instancetype)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self) {        self.imageView.contentMode = UIViewContentModeBottom;        self.titleLabel.textAlignment = NSTextAlignmentCenter;        self.titleLabel.font = [UIFont systemFontOfSize:20];    }    return self;}- (CGRect)imageRectForContentRect:(CGRect)contentRect {    CGFloat ponitX = 0;    CGFloat ponitY = 0;    CGFloat width = contentRect.size.width;    CGFloat height = contentRect.size.height * kScale;    return CGRectMake(ponitX, ponitY, width, height);}- (CGRect)titleRectForContentRect:(CGRect)contentRect {    CGFloat ponitX = 0;    CGFloat ponitY = contentRect.size.height * kScale;    CGFloat width = contentRect.size.width;    CGFloat height = contentRect.size.height * (1 - kScale);    return CGRectMake(ponitX, ponitY, width, height);}@end

在这里调用

 [super viewDidLoad];    NSArray * nameList = @[@"会议信息",@"会议日程",@"会议讲者",@"会议报道",@"论文摘要",@"会议讨论",@"照片墙",@"参会注册",@"地图",@"报名须知"];    NSArray * imageList = @[@"meeting_info_n",@"meeting_schedule_n",@"meeting_guest_n",@"meeting_new_n",@"meeting_other_n",@"meeting_community_n",@"meeting_image_n",@"meeting_register_n",@"meeting_map_n",@"meeting_notice_n"];    CGFloat width = CGRectGetWidth(self.view.frame)/3;    CGFloat height = 150;    for (int i = 0; i < nameList.count; i ++) {        CGFloat ponitX = i % 3;        CGFloat ponitY = i / 3;        CustomButton * btn = [CustomButton buttonWithType:UIButtonTypeCustom];        btn.frame = CGRectMake(ponitX * width, ponitY * height, width, height);        [btn setTitle:nameList[i] forState:UIControlStateNormal];        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];        [btn setImage:[UIImage imageNamed:imageList[i]] forState:UIControlStateNormal];        [btn addTarget:self action:@selector(logTitle:) forControlEvents:UIControlEventTouchUpInside];        [self.view addSubview:btn];    }

宇宙黑客王磊磊

1 0
原创粉丝点击