分类: iOS平台
2013-02-20 00:46:28
7.根据当前键盘的高度来设置UITextField的位置
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
}
- (void)keyboardWillShow:(id)sender {
CGRect keyboardFrame;
[[[((NSNotification *)sender) userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
CGFloat keyboardHeight = CGRectGetHeight(keyboardFrame);
[self.textImageView setFrame:CGRectMake(0, 416-keyboardHeight, 320, 45)];
}
8.view控件加边框
profileImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[profileImageButton.layer setMasksToBounds:YES];
[profileImageButton.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
[profileImageButton.layer setBorderWidth:1.0]; //边框宽度
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){225.0/255.0, 225.0/255.0, 225.0/255.0, 1.0 });
[profileImageButton.layer setBorderColor:colorref];//边框颜色
9.单独设置圆角
[iconImage.layer setCornerRadius:4.0];
[iconImage setClipsToBounds:YES];
10.时区返回格式为数字(-12—+12)
-(NSString *)getTimeZone{
NSString *zone = [[NSTimeZone systemTimeZone] description];//Europe/Berlin// America/New_York// Asia/Harbin
//这三个可以用来测试exp:NSString *zone = [[NSTimeZone timeZoneWithName:@"America/New_York"] description];
NSString *time = [[zone componentsSeparatedByString:@"offset "] objectAtIndex:1];
int inv = [time intValue];
int result = inv / (60 * 60);
if (result>0) {
return [NSString stringWithFormat:@"+%d", result];
}
return [NSString stringWithFormat:@"%d", result];
}
11.检测iphone插入/拔出耳机事件
void audioRouteChangeListenerCallback (
void *inUserData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void *inData)
{
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
CFStringRef state = nil;
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute
,&propertySize,&state);
NSLog(@"%@",(NSString *)state);//return @"Headphone" or @"Speaker" and so on.
}
- (void)viewDidLoad {
[super viewDidLoad];
AudioSessionInitialize (NULL, NULL, NULL, NULL);
OSStatus status = AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,self);
//if(status == 0){//ok;}
}