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
- iOS 第四天之ViewController
- iOS之viewController瘦身
- 【iOS】iOS之viewcontroller详解
- iOS之viewController的生命周期
- 【iOS】iOS之Container View获取ViewController
- iOS开发之Present ViewController Modally --弹出模态ViewController
- iOS 之在一个viewController中添加多个viewController
- iOS开发之Present ViewController Modally --弹出模态ViewController
- iOS开发之Present ViewController Modally --弹出模态ViewController
- iOS入门之UIButton/ViewController/UIImage
- iOS 7 新特性之ViewController切换
- IOS ViewController
- IOS开发(8)之调整ViewController的序列
- IOS开发之获取Storyboard创建的ViewController
- IOS开发之获取Storyboard创建的ViewController
- iOS开发笔记之ViewController视图控制器间的跳转
- iOS开发之ViewController页面跳转和弹出模态
- IOS学习之storyBoard的应用,使用performSegueWithIdentifier來切換ViewController
- Navicat Premium11.0.16 for mac 中文破解版
- hdu 1698 Just a Hook
- Elasticsearch的远程执行漏洞
- 师兄推荐的技术开发文档汇总--网址
- 匿名函数[matlab]
- iOS 第四天之ViewController
- 回文数(二)
- STM32启动过程
- yii 提交表单 400 bad request问题
- python机器学习:从入门到精通
- 网络---XML解析
- 函数极限limit [matlab]
- ZSTU 4213: One-Way Roads【图论】【欧拉回路】
- 尼科彻斯定理