微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > iphone开发中的一些小技巧

iphone开发中的一些小技巧

时间:10-08 来源:互联网 点击:

tionInView:self.listTable];

NSIndexPath *indexPath = [self.listTable indexPathForRowAtPoint: currentTouchPosition];

if (indexPath == nil) {

return;

}

NSInteger section = [indexPath section];

NSUInteger row = [indexPath row];

NSDictionary *rowData = [datas objectAtIndex:row];

NSString *num = [[NSString alloc] initWithFormat:@tel://%@,number]; //number为号码字符串

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //拨号

}

12、更改iphone的键盘颜色:

1.只有这2种数字键盘才有效果。UIKeyboardTypeNumberPad,UIKeyboardTypePhonePad

2. keyboardAppearance = UIKeyboardAppearanceAlert

- (void)textViewDidBeginEditing:(UITextView *)textView{

NSArray *ws = [[UIApplication sharedApplication] windows];

for(UIView *w in ws){

NSArray *vs = [w subviews];

for(UIView *v in vs)

{

if([[NSString stringWithUTF8String:object_getClassName(v)] isEqualToString:@UIKeyboard])

{

v.backgroundColor = [UIColor redColor];

}

}

}

13、设置时区

NSTimeZone *defaultTimeZone = [NSTimeZone defaultTimeZone];

NSTimeZone *tzGMT = [NSTimeZone timeZoneWithName:@GMT];

[NSTimeZone setDefaultTimeZone:tzGMT];

上面两个时区任意用一个。

14、Ipad隐藏键盘的同时触发方法。

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(keyboardWillHide:)

name:UIKeyboardWillHideNotification

object:nil];

- (IBAction)keyboardWillHide:(NSNotification *)note

14、在一个程序中打开另一个程序的方法。

http://www.cocoachina.com/iphonedev/sdk/2010/0322/768.html

15、计算字符串的字数

-(int)calculateTextNumber:(NSString *)text

{

float number = 0.0;

int index = 0;

for (index; index [text length]; index++)

{

NSString *protoText = [text substringToIndex:[text length] - index];

NSString *toChangetext = [text substringToIndex:[text length] -1 -index];

NSString *charater;

if ([toChangetext length]==0)

{

charater = protoText;

}

else

{

NSRange range = [text rangeOfString:toChangetext];

charater = [protoText stringByReplacingCharactersInRange:range withString:@];

}

NSLog(charater);

if ([charater lengthOfBytesUsingEncoding:NSUTF8StringEncoding] == 3)

{

number++;

}

else

{

number = number+0.5;

}

}

return ceil(number);

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top