iOS-App登录界面常用API
2015-12-17 本文已影响1259人
刘栋
[iOS 判断字符串中含有某个字符串 rangeOfString]
//判断useTextFileld.text 是否含有txt
if([useTextFileld.text rangeOfString:@"txt"].location !=NSNotFound)
//_roaldSearchText
{
NSLog(@"yes"); } else { NSLog(@"no"); }
[键盘样式风格有关设置]
一、键盘风格
UIKit框架支持8种风格键盘。
typedef **enum ** {
UIKeyboardTypeDefault, // 默认键盘:支持所有字符
UIKeyboardTypeASCIICapable, // 支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, // 标准电话键盘,支持+*#等符号
UIKeyboardTypeURL, // URL键盘,有.com按钮;只支持URL字符
UIKeyboardTypeNumberPad, //数字键盘 (控制台打印的东西可以不用管)
UIKeyboardTypePhonePad, // 电话键盘
UIKeyboardTypeNamePhonePad, // 电话键盘,也支持输入人名字
UIKeyboardTypeEmailAddress, // 用于输入电子邮件地址的键盘
} UIKeyboardType;
用法用例:
textView.keyboardtype = UIKeyboardTypeNumberPad;
二、键盘外观
typedef **enum ** {
UIKeyboardAppearanceDefault, // 默认外观:浅灰色
UIKeyboardAppearanceAlert, //深灰/石墨色
} UIKeyboardAppearance;
用法用例:
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
三、回车键(右下角的按键)
typedef enum {
UIReturnKeyDefault, //默认:灰色按钮,标有Return
UIReturnKeyGo, //标有Go的蓝色按钮
UIReturnKeyGoogle, //标有Google的蓝色按钮,用于搜索
UIReturnKeyJoin, //标有Join的蓝色按钮
UIReturnKeyNext, //标有Next的蓝色按钮
UIReturnKeyRoute, //标有Route的蓝色按钮
UIReturnKeySearch, //标有Search的蓝色按钮
UIReturnKeySend, //标有Send的蓝色按钮
UIReturnKeyYahoo, //标有Yahoo!的蓝色按钮,用于搜索
UIReturnKeyDone, //标有Done的蓝色按钮
UIReturnKeyEmergencyCall, //紧急呼叫按钮
} UIReturnKeyType;
用法用例:
textView.returnKeyType=UIReturnKeyGo;
四、自动大写
typedef **enum ** {
UITextAutocapitalizationTypeNone, //不自动大写
UITextAutocapitalizationTypeWords, //单词首字母大写
UITextAutocapitalizationTypeSentences, //句子首字母大写
UITextAutocapitalizationTypeAllCharacters, //所有字母大写
} UITextAutocapitalizationType;
用法用例:
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
五、自动更正
typedef **enum ** {
UITextAutocorrectionTypeDefault, //默认
UITextAutocorrectionTypeNo, //不自动更正
UITextAutocorrectionTypeYes, //自动更正
} UITextAutocorrectionType;
用法用例:
textField.autocorrectionType = UITextAutocorrectionTypeYes;
六、安全文本输入(密码是隐藏的)
textView.secureTextEntry=YES;
开启安全输入主要是用于密码或一些私人数据的输入,此时会禁用自动更正和自此缓存
[IOS开发之UIFont应用](http://blog.csdn.net/sanpintian/article/details/7397596)
我们在开发中很多时候要设置UIlabel,UIbutton,UItextfield的字体,这个时候我们就需要用到UIFont,下面简单介绍一下UIFont的用法,仅供参考。
UIFont用于获取和设置字体信息。这个类提供用于输出的字体的属性和字型信息。我们可以把其对象像参数一样传入函数中。
一般而言我们不需要用alloc,int方法初始化UIFont对象,我们用UIFont大部分的时候是用其类方法,这些方法会设置对象的属性,且返回一个字体对象。
例如:
_centerLabel = [[UILabel alloc] initWithFrame:CGRectMake(115, 12, 85, 21)];
_centerLabel.text = @"经销商查询";
[_centerLabel setFont:[UIFont fontWithName:@"Helvetica" size:17.0]];
[self.view addSubview:_centerLabel];
下面两个函数创建字体:
+fontWithName:(NSString *)fontName size:(CGFloat) fontSize 创建并且返回一个指定字体类型和大小的字体对象,fontName指定字体集的名字和风格(例如宋体,楷书等这一类型的),fontsize设置字体的大小。
-fontWithSize:返回字体的大小
上面我们提到我们需要设置字体集,在IOS系统中我们用到的字体包含一下几种 :
Font Family: American Typewriter( AmericanTypewriter,AmericanTypewriter-Bold)
Font Family: AppleGothic(AppleGothic)
Font Family: Arial(ArialMT,Arial-BoldMT,Arial-BoldItalicMT,Arial-ItalicMT)
Font Family: Arial Rounded MT Bold(ArialRoundedMTBold)
Font Family: Arial Unicode MS(ArialUnicodeMS)
Font Family: Courier(Courier,Courier-BoldOblique,Courier-Oblique,Courier-Bold)
Font Family: Courier New(CourierNewPS-BoldMT,CourierNewPS-ItalicMT,CourierNewPS-BoldItalicMT,CourierNewPSMT)
Font Family: DB LCD Temp (DBLCDTempBlack)
Font Family: Georgia( Georgia-Bold, Georgia,Georgia-BoldItalic,Georgia-Italic)
Font Family: Helvetica(Helvetica-Oblique,Helvetica-BoldOblique,Helvetica,Helvetica-Bold) 默认字体Font Family: Helvetica Neue(HelveticaNeue,HelveticaNeue-Bold)Font Family: Hiragino Kaku Gothic **** W3(HiraKakuProN-W3)
Font Family: Hiragino Kaku Gothic **** W6(HiraKakuProN-W6)
Font Family: Marker Felt( MarkerFelt-Thin)
Font Family: STHeiti J (STHeitiJ-Medium,STHeitiJ-Light)
Font Family: STHeiti K( STHeitiK-Medium, STHeitiK-Light)
Font Family: STHeiti SC(STHeitiSC-Medium, STHeitiSC-Light)
Font Family: STHeiti TC(STHeitiTC-Light,STHeitiTC-Medium)
Font Family: Times New Roman(TimesNewRomanPSMT,TimesNewRomanPS-BoldMT, TimesNewRomanPS-BoldItalicMT, TimesNewRomanPS-ItalicMT)
Font Family: Trebuchet MS( TrebuchetMS-Italic,TrebuchetMS,Trebuchet-BoldItalic,TrebuchetMS-Bold)Font Family: Verdana( Verdana-Bold,Verdana-BoldItalic, Verdana,Verdana-Italic)Font Family: Zapfino( Zapfino)
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize 使用标准的接口返回指定大小的字体对象。
+ (CGFloat)systemFontSize 返回标准的系统字体大小。
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize 返回字体对象使用了标准接口来指定字体大小附加黑体风格。
+ (CGFloat)buttonFontSize 返回按钮使用标准字体。
+ (NSArray *)familyNames 返回系统可用字体集名称的数组。一个NSString型数组对象。每一个元素包含了字型集名称。字型集的名称相当于字型的基础名称。如 Times New Roman.你可以输入返回的字符串到 fontNamesForFamilyName: 方法来取得可用的字型集的名称。然後你可以用这些恰当的名称去取得字体对象。
+ (NSArray *)fontNamesForFamilyName:(NSString *)familyName )familyName字体集的名称。使用 familyNames 方法取得系统中的一个字体集的名称。
//修改NavigationBar
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:@ "STHeiti TC" size:16.0], NSFontAttributeName, nil]];
实现对textField输入到一定字符的时候Button变色
Button变色.gif
//用到监听文本框的方法
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(registerTextFieldTextDidChangeNotification:)
name:UITextFieldTextDidChangeNotification object:nil];
-(void)registerTextFieldTextDidChangeNotification:(NSNotification *)natification{
if (self.textFieldRegister.text.length >= 11) {
self.textFieldRegister.text = [NSString stringWithFormat:@"%@",[self.textFieldRegister.text substringToIndex:11]];
}
if (self.textFieldRegister.text.length == 11) {
self.buttonGain.backgroundColor = [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000];
[self.buttonGain addTarget:self action:@selector(handleSend:) forControlEvents:UIControlEventTouchUpInside];
}
else{
self.buttonGain.backgroundColor = [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:0.3];
[self.buttonGain removeTarget:self action:@selector(handleSend:) forControlEvents:UIControlEventTouchUpInside];
}
}
[ios 限制只能输入字母和数字]
//数字#define NUM @"0123456789"
//字母#define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"//数字和字母#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
//UITextField代理方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSCharacterSet *cs;
//让哪个实现这个限制
if (textField == self.textFieldRegister) {
cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
}
else{
cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum]invertedSet];
}
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
BOOL canChange = [string isEqualToString:filtered];
return canChange;
}
[触发键盘右下角的return的事件, 切换到下一个文本框]
return触发事件.gif
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.textFieldUser) {
[self.textFieldPassword becomeFirstResponder];
}
else if (textField == self.textFieldPassword){
NSLog(@"GO");
}
return YES;
}
[改变self.navigationItem.rightBarButtonItem的字体颜色]
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor colorWithWhite:0.549 alpha:1.000]];
定制文本框光标颜色
_usernameTextField.tintColor = [UIColor greenColor];
设置button背景图片的颜色
[backButton setImage:[[UIImage imageNamed:@"back.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
backButton.imageView.tintColor = [UIColor blackColor];
改变searchBar的背景图
[_searchBar setSearchFieldBackgroundImage:
[UIImage imageNamed:@"gray"] forState:UIControlStateNormal];
更改NavigationBar下划线颜色
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
NSArray *list=self.navigationController.navigationBar.subviews;
for (id obj in list) {
if ([obj isKindOfClass:[UIImageView class]]) {
UIImageView *imageView=(UIImageView *)obj;
NSArray *list2=imageView.subviews;
for (id obj2 in list2) {
if ([obj2 isKindOfClass:[UIImageView class]]) {
UIImageView *imageView2=(UIImageView *)obj2;
imageView2.hidden=YES;
}
}
}
}
}