1:如何给表格单元列增加选择时的背影效果

  1. if (cell == nil) {
  2. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  3. cell.backgroundColor = [UIColor clearColor];
  4. cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:];
  5. cell.textLabel.textColor = [UIColor whiteColor];
  6. cell.textLabel.highlightedTextColor = [UIColor lightGrayColor];
  7. UIView *sbg=[[UIView alloc] initWithFrame:cell.frame];
  8. sbg.backgroundColor=[UIColor colorWithWhite:0.5 alpha:0.3];
  9. cell.selectedBackgroundView = sbg;
  10. }

2:修改标题栏的文字

  1. UIColor *cc = [UIColor whiteColor];
  2. NSDictionary * dict = [NSDictionary dictionaryWithObject:cc forKey:UITextAttributeTextColor];
  3. self.navigationController.navigationBar.titleTextAttributes = dict;

3:一个滚动启动页功能代码

  1. #define NewFeatureCount 4
  2.  
  3. @interface HVWNewFeatureViewController () <UIScrollViewDelegate>
  4.  
  5. @property(nonatomic, strong) UIPageControl *pageControl;
  6.  
  7. @end
  8.  
  9. @implementation HVWNewFeatureViewController
  10.  
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. // Do any additional setup after loading the view.
  14.  
  15. // 添加scrollView
  16. [self setupScrollView];
  17.  
  18. // 添加pageControl
  19. [self setupPageControl];
  20. }
  21.  
  22. /** 添加scrollView */
  23. - (void) setupScrollView {
  24. // 创建一个scrollView
  25. UIScrollView *scrollView = [[UIScrollView alloc] init];
  26. scrollView.frame = self.view.bounds;
  27.  
  28. // 添加图片
  29. for (int i=; i<NewFeatureCount; i++) {
  30.  
  31. // 获取图片
  32. NSString *featureImageName = [NSString stringWithFormat:@"new_feature_%d", i+];
  33. UIImageView *featureImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithNamed:featureImageName]];
  34.  
  35. // 设置图片尺寸位置
  36. CGFloat featureWidth = self.view.width;
  37. CGFloat featureHeight = self.view.height;
  38. CGFloat featureX = featureImageView.width * i;
  39. CGFloat featureY = ;
  40. featureImageView.frame = CGRectMake(featureX, featureY, featureWidth, featureHeight);
  41.  
  42. // 如果是最后一页,加上功能按钮
  43. if (i == (NewFeatureCount - )) {
  44. // 为了让最后一页的的功能按钮能够生效,必须激活交互功能
  45. featureImageView.userInteractionEnabled = YES;
  46.  
  47. [self addFunctionButton:featureImageView];
  48. }
  49.  
  50. // 添加图片到scrollView
  51. [scrollView addSubview:featureImageView];
  52. }
  53.  
  54. // 设置scrollView功能属性
  55. scrollView.userInteractionEnabled = YES;
  56. scrollView.scrollEnabled = YES; // 支持滚动
  57. scrollView.contentSize = CGSizeMake(self.view.width * NewFeatureCount, ); // 只需要水平滚动
  58. scrollView.pagingEnabled = YES; // 支持分页
  59. scrollView.showsHorizontalScrollIndicator = NO; // 隐藏水平滚动条
  60.  
  61. // 设置背景色
  62. scrollView.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:1.0];
  63.  
  64. // 设置代理
  65. scrollView.delegate = self;
  66.  
  67. // 添加
  68. [self.view addSubview:scrollView];
  69. }
  70.  
  71. /** 添加pageControl */
  72. - (void) setupPageControl {
  73. // pageControl不能加在scrollView上,不然会随着内容一起滚动
  74. UIPageControl *pageControl = [[UIPageControl alloc] init];
  75. pageControl.pageIndicatorTintColor = [UIColor blackColor];
  76. pageControl.currentPageIndicatorTintColor = [UIColor redColor];
  77. pageControl.numberOfPages = NewFeatureCount;
  78.  
  79. // 设置位置
  80. pageControl.centerX = self.view.width * 0.5;
  81. pageControl.centerY = self.view.height * 0.9;
  82.  
  83. self.pageControl = pageControl;
  84. [self.view addSubview:pageControl];
  85. }
  86.  
  87. #pragma mark - UIScrollViewDelegate
  88. /** scrollView滚动代理方法,在这里控制页码指示器 */
  89. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  90. // 四舍五入,让图片滚动超过中线的时候改变页码
  91. self.pageControl.currentPage = scrollView.contentOffset.x / scrollView.width + 0.5;
  92. }
  93.  
  94. #pragma mark - 最后一页的功能
  95. /** 添加功能按钮 */
  96. - (void) addFunctionButton:(UIImageView *) imageView {
  97. // 添加"分享"选项按钮
  98. [self addShareButton:imageView];
  99.  
  100. // 添加"进入微博"按钮
  101. [self addEnterWeiboButton:imageView];
  102. }
  103.  
  104. /** 分享选项按钮 */
  105. - (void) addShareButton:(UIImageView *) imageView {
  106. // 创建按钮
  107. UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
  108.  
  109. [shareButton setTitle:@"分享给大家" forState:UIControlStateNormal];
  110.  
  111. [shareButton setImage:[UIImage imageWithNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
  112. [shareButton setImage:[UIImage imageWithNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
  113.  
  114. [shareButton addTarget:self action:@selector(shareButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  115.  
  116. [shareButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  117.  
  118. // 位置尺寸
  119. shareButton.size = CGSizeMake(, );
  120.  
  121. // 必须先设置了size,center才真的在中心,不然就是从左上角开始!!!
  122. shareButton.centerX = self.view.width * 0.5;
  123. shareButton.centerY = self.view.height * 0.65;
  124.  
  125. // 设置内间距
  126. shareButton.titleEdgeInsets = UIEdgeInsetsMake(, 10.0, , );
  127.  
  128. // 添加
  129. [imageView addSubview:shareButton];
  130. }
  131.  
  132. /** 分享选项点击事件方法 */
  133. - (void) shareButtonClicked:(UIButton *) button {
  134. button.selected = !button.selected;
  135. }
  136.  
  137. /** “进入微博"按钮 */
  138. - (void) addEnterWeiboButton:(UIImageView *) imageView {
  139. // 创建按钮
  140. UIButton *enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
  141. enterButton.userInteractionEnabled = YES;
  142. [enterButton setBackgroundImage:[UIImage imageWithNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
  143. [enterButton setBackgroundImage:[UIImage imageWithNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
  144. [enterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  145. [enterButton setTitle:@"进入微博" forState:UIControlStateNormal];
  146.  
  147. // 位置尺寸
  148. enterButton.size = enterButton.currentBackgroundImage.size;
  149. enterButton.centerX = self.view.width * 0.5;
  150. enterButton.centerY = self.view.height * 0.8;
  151.  
  152. // 监听点击
  153. [enterButton addTarget:self action:@selector(enterWeiboButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  154.  
  155. // 添加
  156. [imageView addSubview:enterButton];
  157. }
  158.  
  159. /** “进入微博” 按钮点击 */
  160. - (void) enterWeiboButtonClicked {
  161. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  162. window.rootViewController = [[HVWTabBarViewController alloc] init];
  163. }
  164.  
  165. @end

4:增加删除控制器

  1. 增加控制器:
  2.  
  3. [self addChildViewController:toViewController];
  4. [toViewController didMoveToParentViewController:self];
  5.  
  6. 小实例:
  7.  
  8. - (IBAction)btnAction:(id)sender {
  9. CiderViewController *cid=[[CiderViewController alloc] init];
  10. [self addChildViewController:cid];
  11. CGRect frame=self.myView.bounds;
  12. frame.origin.y=;
  13. frame.size.width=;
  14. frame.size.height=;
  15.  
  16. cid.view.frame=frame;
  17. cid.view.backgroundColor=[UIColor redColor];
  18. [self.myView addSubview:cid.view];
  19. [cid didMoveToParentViewController:self];
  20. }
  21.  
  22. 删除控制器:
  23.  
  24. .当我们向我们的视图控制器容器中调用removeFromParentViewController方法时,必须要先调用该方法,且parent参数为nil
  25. [将要删除的视图控制器 willMoveToParentViewController:nil];
  26.  
  27. [fromViewController willMoveToParentViewController:nil];
  28. [fromViewController removeFromParentViewController];Í
  29.  
  30. 一些说明:
  31.  
  32. 关于willMoveToParentViewController方法和didMoveToParentViewController方法的使用
  33.  
  34. .这两个方法用在子试图控制器交换的时候调用!即调用transitionFromViewController 方法时,调用。
  35.  
  36. .当调用willMoveToParentViewController方法或didMoveToParentViewController方法时,要注意他们的参数使用:
  37. 当某个子视图控制器将从父视图控制器中删除时,parent参数为nil
  38. 即:[将被删除的子试图控制器 willMoveToParentViewController:nil];
  39. 当某个子试图控制器将加入到父视图控制器时,parent参数为父视图控制器。
  40. 即:[将被加入的子视图控制器 didMoveToParentViewController:父视图控制器];
  41.  
  42. .无需调用[子视图控制器 willMoveToParentViewController:父视图控制器]方法。因为我们调用[父视图控制器 addChildViewController:子视图控制器]时,已经默认调用了。
  43. 只需要在transitionFromViewController方法后,调用[子视图控制器didMoveToParentViewController:父视图控制器];
  44.  
  45. .无需调用[子视图控制器 didMoveToParentViewController:父视图控制器]方法。因为我们调用
  46. [子视图控制器 removeFromParentViewController]时,已经默认调用了。
  47. 只需要在transitionFromViewController方法之前调用:[子视图控制器 willMoveToParentViewController:nil]。
  48.  
  49. 不错的文章(http://www.cocoanetics.com/2012/04/containing-viewcontrollers/ http://mobile.51cto.com/iphone-313146.htm)

5:关于UIView的autoresizingMask属性的研究

  1. UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高。
  2.  
  3. enum {
  4.    UIViewAutoresizingNone                 = ,
  5.    UIViewAutoresizingFlexibleLeftMargin   = << ,
  6.    UIViewAutoresizingFlexibleWidth        = << ,
  7.    UIViewAutoresizingFlexibleRightMargin  = << ,
  8.    UIViewAutoresizingFlexibleTopMargin    = << ,
  9.    UIViewAutoresizingFlexibleHeight       = << ,
  10.    UIViewAutoresizingFlexibleBottomMargin = <<
  11. };
  12.  
  13. UIViewAutoresizingNone就是不自动调整。
  14. UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。
  15. UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。
  16. UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。
  17. UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
  18. UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。
  19. UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。
  20. UIViewAutoresizingFlexibleLeftMargin  |UIViewAutoresizingFlexibleRightMargin 自动调整与superView左边的距离,保证与左边的距离和右边的距离和原来距左边和右边的距离的比例不变。比如原来距离为20,,调整后的距离应为68,,即68/=/。
  21. 其它的组合类似。
  22.  
  23. 实例:
  24.  
  25. CGRect frame = [[UIScreen mainScreen] applicationFrame];
  26. UIView *view = [[UIView alloc] initWithFrame:frame];
  27. view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

6:系统提供的dispatch方法

  1. 为了方便地使用GCD,苹果提供了一些方法方便我们将block放在主线程 后台线程执行,或者延后执行。使用的例子如下:
  2.  
  3. //  后台执行: 
  4.  dispatch_async(dispatch_get_global_queue(, ), ^{ 
  5.       // something 
  6.  }); 
  7.  // 主线程执行: 
  8.  dispatch_async(dispatch_get_main_queue(), ^{ 
  9.       // something 
  10.  }); 
  11.  // 一次性执行: 
  12.  static dispatch_once_t onceToken; 
  13.  dispatch_once(&onceToken, ^{ 
  14.      // code to be executed once 
  15.  }); 
  16.  // 延迟2秒执行: 
  17.  double delayInSeconds = 2.0; 
  18.  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
  19.  dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
  20.      // code to be executed on the main queue after delay 
  21.  }); 
  22.  
  23. dispatch_queue_t 也可以自己定义,如要要自定义queue,可以用dispatch_queue_create方法,示例如下:
  24.  
  25. dispatch_queue_t urls_queue = dispatch_queue_create("blog.devtang.com", NULL); 
  26. dispatch_async(urls_queue, ^{ 
  27.      // your code 
  28. }); 
  29. dispatch_release(urls_queue); 
  30.  
  31. 另外,GCD还有一些高级用法,例如让后台2个线程并行执行,然后等2个线程都结束后,再汇总执行结果。这个可以用dispatch_group, dispatch_group_async dispatch_group_notify来实现,示例如下:
  32.  
  33. dispatch_group_t group = dispatch_group_create(); 
  34. dispatch_group_async(group, dispatch_get_global_queue(,), ^{ 
  35.       // 并行执行的线程一 
  36.  }); 
  37.  dispatch_group_async(group, dispatch_get_global_queue(,), ^{ 
  38.       // 并行执行的线程二 
  39.  }); 
  40.  dispatch_group_notify(group, dispatch_get_global_queue(,), ^{ 
  41.       // 汇总结果 
  42.  }); 

IOS开发基础知识--碎片10的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  3. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

  4. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  5. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  6. IOS开发基础知识--碎片47

    1:解决ios静态库中的类别(category)在工程中不能使用 解决方法为:找到 target 的图标,更改其 Other Linker Flags 为: -all_load 或 -force_lo ...

  7. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  8. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  9. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

随机推荐

  1. Android 如何制作九宫格图片(.9.png)

    对于编程人员来说,尤其是前端设计设计师,九宫格图片是必须的(.9.png),对于初学者来说不知道这个九宫格图片有什么用,其实这个九宫格图片实际常用在Android的button组件.要上下拉升的背景图 ...

  2. 一起学微软Power BI系列-官方文档-入门指南(6)Power BI与Excel

    今天介绍了官方入门文档中有关PowerBI和Excel的知识.前几篇入门文档有点仓促,加上最近时间的研究,会有更多技巧性和入门型的文章或者视频发布,最后2篇入门文档将更加详细一点,因为部分文章进行简单 ...

  3. IOS数据存储之FMDB数据库

    前言: 最近几天一直在折腾数据库存储,之前文章(http://www.cnblogs.com/whoislcj/p/5485959.html)介绍了Sqlite 数据库,SQLite是一种小型的轻量级 ...

  4. ASP.NET Core的配置(2):配置模型详解

    在上面一章我们以实例演示的方式介绍了几种读取配置的几种方式,其中涉及到三个重要的对象,它们分别是承载结构化配置信息的Configuration,提供原始配置源数据的ConfigurationProvi ...

  5. web前端基础知识总结

    上个寒假总结的web前端的一些知识点给大家分享一下 1.<html>和</html> 标签限定了文档的开始和结束点. 属性: (1)  dir: 文本的显示方向,默认是从左向右 ...

  6. C语言 第三章 基础编程测试与练习

    1.屏幕上输出:This is a C program 2.输入两个整数,求两个数的和,如下所示:请输入第1个数:5请输入第2个数:3 3加5的和是8 3.完成华氏温度与摄氏温度间的转换,如下所示:请 ...

  7. ACM-东北大学程序设计竞赛-网络赛(2016.04.16)

    Problem: A Time limit: 1s    Mem limit: 64 MB    AC/Submission: 0/0    Discuss Back   Ranklist  Stat ...

  8. 使用FlexPaper实现office文件的预览(C#版)

    需求很简单,用户上传office文件(word.excel.ppt)后,可以预览上传的这些文件.搜索的相关的资料后.整理如下: Step1.用户上传office文件. Step2.把Office文件转 ...

  9. JS实现返回对象的详细信息

    使用JS有时会需要打印出对象的详细信息,下面方法可以实现: function ShowObjProperty(Obj) { var PropertyList=''; var PropertyCount ...

  10. 那些年用过的xUnit.net的简单用法

    0x01 前言 单元测试,总是伴随着我们的开发过程,优劣自行google.当然呢,不排除有些公司是不做单元测试的, 但是呢,学多一点东西用来防身还是可以的. 0x02 简单的Demo 写个两数求和的方 ...