iOS笔记(常用的一些知识点)

 这是我在公司做项目时,顺便做的一些笔记.......

//1.iphone开发--改变UIPageControl里的小点的颜色

pageControl.currentPageIndicatorTintColor = [UIColor blackColor];

pageControl.pageIndicatorTintColor = [UIColor grayColor];


//2.ios如何让状态栏变成白色的

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

如果不行,请在info.plist里面添加 View controller-based status bar appearance   NO

可以参考http://beyondvincent.com/blog/2013/11/03/120-customize-navigation-status-bar-ios-7/


//3.如:修改导航栏默认标题"忆云美印"的颜色和字体

self.title=@"忆云美印";

self.navigationController.navigationBar.titleTextAttributes=@{UITextAttributeTextColor:[UIColor whiteColor],UITextAttributeFont:[UIFont boldSystemFontOfSize:20]};


//4.给label设置圆角

label.layer.borderWidth=1.0f;

label.layer.cornerRadius=5.0f;


//5.手动旋转状态栏必须实现下面的方法

- (BOOL)shouldAutorotate

{

    return NO;

}

- (NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskPortrait;

}


//6.如何设置只能竖屏显示

修改info.plist里面supportedInterfaceOrientations设置item为portrait就可以了,这个设置为全局.


//7.利用UIColor展现#f6f6f6这个传统颜色转换为十进制f6为240

则UIColor *color=[UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];


//8.创建类目,延展,协议,空文件

cmd+n 选择ios Source里面的objective-c File -> File Type的类型(类目,延展,协议,空文件)


//9.把视图转换为图片

//把视图转换为图片

UIGraphicsBeginImageContext(oppositeImageView.bounds.size);

[oppositeImageView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *oppositeImg=UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();


//10.实现图片视图的拖动效果

- (void)viewDidLoad {

    [super viewDidLoad];

    //创建图片视图

    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 150)];

    imageView.userInteractionEnabled=YES;

    imageView.image=[UIImage imageNamed:@"ad_1"];

    

    //平移手势

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

    [imageView addGestureRecognizer:pan];

    [self.view addSubview:imageView];

}

//平移手势的拖动事件

- (void)panAction:(UIPanGestureRecognizer *)pan

{

    CGPoint point=[pan translationInView:self.view];

    pan.view.center=CGPointMake(pan.view.center.x+point.x, pan.view.center.y+point.y);

    [pan setTranslation:CGPointZero inView:self.view];

}

//11.图片可以响应事件,如 UITextView添加到图片可以进行拖动.

backgrondImage.userInteractionEnabled=YES;

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。