开发常用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发常用相关的知识,希望对你有一定的参考价值。
@font-face { font-family: "宋体"; }@font-face { font-family: "宋体"; }@font-face { font-family: "@宋体"; }@font-face { font-family: "Cambria"; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm 0cm 0.0001pt; text-align: justify; font-size: 12pt; font-family: Cambria; }.MsoChpDefault { font-family: Cambria; }div.WordSection1 { }
textView自适应高度
-(void)textViewDidChange:(UITextView *)textView{
CGFloat h = 0;
if (textView.text.length == 0) {
h = 30;
}else{
h = textView.contentSize.height;
}
CGRect temp = textView.frame;
temp.size.height = h;
textView.frame = temp;
}
计算文字高度
- (CGFloat)stringHeight:(NSString *)aString
{
// 计算文字高度
CGRect r = [aString boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width - 20, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0f]} context:nil];
return r.size.height;
}
输入框键盘上”完成”收键盘
UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
iv.backgroundColor = [UIColor colorWithRed:210 / 255.0 green:213 / 255.0 blue:220 / 255.0 alpha:1];
UIButton *textFieldSureButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
textFieldSureButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 50, 0, 50, 40);
[textFieldSureButton setTitle:@"完成" forState:(UIControlStateNormal)];
[textFieldSureButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
[textFieldSureButton addTarget:self action:@selector(dissmissKeyBoard) forControlEvents:(UIControlEventTouchUpInside)];
[iv addSubview:textFieldSureButton];
textView.inputAccessoryView = iv;
textView.delegate=self;
方法
-(void)dissmissKeyBoard{
[textView resignFirstResponder];
}
//***获取字符串
NSString *str=tf.text;
//***调用关键方法,获得bool值,yes或者no:
BOOL ok= [self isIncludeSpecialCharact:str];
if (ok==YES) {
NSLog(@"包含有特殊字符");
}else{
NSLog(@"不包含特殊字符");
}
//***关键方法
-(BOOL)isIncludeSpecialCharact: (NSString *)str {
//***需要过滤的特殊字符:~¥#&*<>《》()[]{}【】^@/£¤¥|§¨「」『』¢¬ ̄[email protected]#¥&*()——+|《》$_€。
NSRange urgentRange = [str rangeOfCharacterFromSet: [NSCharacterSet characterSetWithCharactersInString: @"~¥#&*<>《》()[]{}【】^@/£¤¥|§¨「」『』¢¬ ̄[email protected]#¥&*()——+|《》$_€"]];
if (urgentRange.location == NSNotFound)
{
return NO;
}
return YES;
}
字典变json
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:0 error:nil];
NSLog(@"%@",[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
以上是关于开发常用的主要内容,如果未能解决你的问题,请参考以下文章
php开发常用的实用方法(第一节)(电商开发微信支付宝开发常用)