您的位置:首页 > 移动开发 > IOS开发

ios开发过程中的一些笔记,不断更新中。。。

2015-09-29 13:50 363 查看
记录学习中的点点滴滴:

1、一个类,无论是继承自nsobject还是继承自uiviewcontroller,初始化一些东西时,难免需要程序运行后只走一遍,例如一些页面的初始值,一些model的初始值。当我们需要只是运行程序就会初始化一次时,我们可以调用这两个方法:

+(void)initialize{

}

+(void)load{

}
这两个方法,在程序运行后会执行,而且只会执行一次

2、设置button的标题与button的边界的距离,例如不是设置标题居中的,而是标题离右边界的距离为30像素,那么需要先设置button的内容的对齐方式
[b]startButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;[/b]

然后,定义一个UIEdgeInsets

UIEdgeInsets edgeInset =UIEdgeInsetsMake(0,0,0,30);

最后设置button的titleEdgeInsets为自己定义的UIEdgeInsets

startButton.titleEdgeInsets = edgeInset

成功!!

3、设置UIDatePicker的显示中英文问题

NSLocale *locale = [[NSLocalealloc]initWithLocaleIdentifier:@"en_US"];//设置为英文显示
NSLocale *locale = [[NSLocalealloc]initWithLocaleIdentifier:@"zh_CN"];//设置为中文显示
datePicker.locale = locale;

ok!!!

4、设置UIDatePicker的显示
// 0-大背景的颜色; 1-选择框左边的颜色;
2-? ;3-?; 5-滚动区域的颜色 回覆盖数据
//6-选择框的背景颜色 7-选择框左边的颜色
8-整个View的颜色 会覆盖所有的图片

UIView *view = [[self subviews] objectAtIndex:6];

[view setBackgroundColor:[UIColor clearColor]];

UIImageView *bgimg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"picker_tiao.png"]];

bgimg.frame = CGRectMake(-5, -3, 200, 55);

[view addSubview:bgimg];

[self setNeedsDisplay];

ok!!!
5、获取键盘的高度
首先注册一个通知,当键盘弹出的时候通知我

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];

然后,当键盘弹出的时候,通过objectForKey:的UIKeyboardFrameBeginUserInfoKey对应的值来获取键盘的高度

- (void) keyboardWasShown:(NSNotification *) notif{

NSDictionary *info = [notif userInfo];

NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];

CGSize keyboardSize = [value CGRectValue].size;

NSLog(@"keyBoard:%f", keyboardSize.height); //216

keyboardWasShown = YES;

}

OK!!!

6、让一个图片不断旋转

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumbernumberWithFloat:M_PI
*2.0 ];

[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotationAnimation.duration =10;
rotationAnimation.repeatCount =9999;//你可以设置到最大的整数值
rotationAnimation.cumulative =NO;
rotationAnimation.removedOnCompletion =NO;
rotationAnimation.fillMode =kCAFillModeForwards;
[self.weatherImageView.layeraddAnimation:rotationAnimationforKey:@"Rotation"];

7、修改pagecontrol的圆点的颜色

UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame: ... pageControl.numberOfPages = 5;

pageControl.currentPageIndicatorTintColor
= [UIColor redColor];

pageControl.pageIndicatorTintColor = [UIColor greenColor];

搞定了!!

8、判断当前设备是否为iphone

[[UIDevicecurrentDevice]
userInterfaceIdiom] ==UIUserInterfaceIdiomPhone

[[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad 判断当前设备是否为ipad

9、让一个图片围绕一个点旋转

-(void)startAnimation

{

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.05];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(startAnimation)];

self.angle += 5;

self.saomiao.layer.anchorPoint = CGPointMake(1,1);//以右下角为原点转,(0,0)是左上角转,(0.5,0,5)心中间转,其它以此类推

self.saomiao.transform = CGAffineTransformMakeRotation(self.angle * (M_PI / 180.0f));
[code][UIView commitAnimations];


}

不断更新中。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: