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;