目录:

一、UINavigationController导航视图控制器

二、NSAttributeString属性字符串

三、UIImageView图像处理

回到顶部

一、UINavigationController导航视图控制器

1 定义:导航视图控制器是控制另外控制器的控制器

2 作用:导航,管理多个视图控制器的跳转,比如我们自己控制视图控制器的跳转更清晰

3 怎么用:创建UINavigationController有一个初始化方法initWithRootViewController:被控制的控制器

* 把navigationcontroller设置成window的根视图

* 从navigationcontroller中跳转到另一个视图控制器:pushViewController

* 从navigationcontroller返回上一个视图控制器:popViewController

在storyboard中设置navigation

editor  ->  embedin ->  navigationController

4 在empty中使用代码添加navigation

在AppDelegate.m中

//UINavigationController

MXFistViewController* fistViewController = [[MXFistViewController alloc] initWithNibName:@"MXFistViewController" bundle:nil];

UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:fistViewController];

self.window.rootViewController = navi;

5 内部原理

* navigation根view不能pop

* navigation维护着一个VC栈,先进后出

* navi必须有一个根视图,创建navi时一般会直接指定

* push一个VC时,上一个VC不会被释放

* navi会保存push进去的VC引用计数器

* pop出来的VC会立即被释放

* 不能pop根视图

6 深入理解navi

* .title  .leftBarButtonItem  .leftBarButtonItems  .toolBarItems这些属性设置在具体的某一个被navi包含的VC,不是设置在navi上

* 具体的VC 上的toolbar默认是隐藏的,如果显示需要调用一个方法[self.navigationController setToolbarHidden:NO]

* UIBarButtonItem 不管是Navigation还是toolbar其中的按键都要用UIBarButton

initWithSystemItem:...设置系统内置按钮

initWithTitle:...文字按钮

initWithImage...图片按钮

- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置navigation标题
    self.title = @"好友圈";
    //设置navigation左右按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(writeWeibo:)];
    //self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil action:nil];
    UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"one" style:UIBarButtonItemStyleBordered target:nil action:nil];
    UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithTitle:@"two" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    self.navigationItem.rightBarButtonItems = @[button1,button2];
    
    //工具条
    UIBarButtonItem* button3 = [[UIBarButtonItem alloc] initWithTitle:@"首页" style:UIBarButtonItemStyleBordered target:nil action:nil];
    UIBarButtonItem* button4 = [[UIBarButtonItem alloc] initWithTitle:@"消息" style:UIBarButtonItemStyleBordered target:nil action:nil];
    //fixed固定
    UIBarButtonItem* fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fixed.width = 20;//设置固定宽度
    //flexible灵活
    UIBarButtonItem* flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    //添加工具条中的按钮
    self.toolbarItems = @[fixed,button3,flexible,button4,fixed];
    // Do any additional setup after loading the view from its nib.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //显示工具条
    [self.navigationController setToolbarHidden:NO animated:YES];
}

-(void)writeWeibo:(UIBarButtonItem*)button{
    MXSecondViewController* second = [[MXSecondViewController alloc] initWithNibName:@"MXSecondViewController" bundle:nil];
    //跳转到另一个view
    //[self.navigationController pushViewController:second animated:YES];

//跳转到被navigation包含的一个view
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:second];
    [self presentViewController:navi animated:YES completion:nil];
    
}

回到顶部

二、NSAttributeString属性字符串

1 ios6中开始ios7加强

2 在NSString的基础上,加入了属性的功能,字体,颜色,加粗,描边,等

MXAttributeViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setup];
    UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"stats" style:UIBarButtonItemStyleBordered target:self action:@selector(statsTap:)];
    //设置导航控制器的右边的button
    self.navigationItem.rightBarButtonItem = button;
}
-(void)statsTap:(UIBarButtonItem*)button{
    MXTextStatsViewController *text = [[MXTextStatsViewController alloc] initWithNibName:@"MXTextStatsViewController" bundle:nil];
    text.textToAnglyze = self.body.textStorage;//传值
    //
    [self.navigationController pushViewController:text animated:YES];
}

-(void)setup{
    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"outline" attributes:@{NSStrokeWidthAttributeName: @-3,NSStrokeColorAttributeName:self.outlineButton.tintColor}];
    [self.outlineButton setAttributedTitle:title forState:UIControlStateNormal];
}

//改变textView中被选择字体颜色
- (IBAction)changeSelectedColor:(UIButton *)sender {
    //Storage中文是存储 仓库
    [self.body.textStorage addAttribute:NSForegroundColorAttributeName value:sender.backgroundColor range:self.body.selectedRange];
}
//加粗textView中被选择字体
- (IBAction)outlineSelect:(UIButton *)sender {
    //[self.body.textStorage addAttributes:@{NSStrokeColorAttributeName: [UIColor blackColor],NSStrokeWidthAttributeName:[NSNumber numberWithInteger:3]} range:self.body.selectedRange];
    [self.body.textStorage addAttributes:@{NSStrokeColorAttributeName: [UIColor blackColor],NSStrokeWidthAttributeName:@-3} range:self.body.selectedRange];
}
//取消加粗
- (IBAction)unoutlineSelect:(UIButton *)sender {
    [self.body.textStorage removeAttribute:NSStrokeWidthAttributeName range:self.body.selectedRange];
}

MXTextStatsViewController.m

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self updateUI];
}
-(void)updateUI{
    self.colorfulLabel.text = [NSString stringWithFormat:@"%d colorful charactrors",[self charactersWithAttribute:NSForegroundColorAttributeName].length];
    self.outlineLabel.text = [NSString stringWithFormat:@"%d outline charactors",[self charactersWithAttribute:NSStrokeWidthAttributeName].length];
}
//
-(NSAttributedString*)charactersWithAttribute:(NSString*)attributeName{
    //创建属性字符串
    NSMutableAttributedString *characters = [[NSMutableAttributedString alloc] init];
    NSUInteger index = 0;
    while ([self.textToAnglyze length] > index) {
        NSRange range;
        //把下标为index有attributeName这个属性的位置和长度 保存在range指向的地址中
        id value = [self.textToAnglyze attribute:attributeName atIndex:index effectiveRange:&range];
        if (value) {

    //添加range范围内的属性字符串到characters
            [characters appendAttributedString:[self.textToAnglyze attributedSubstringFromRange:range]];
            index = range.location + range.length;
        }else{
            index++;
        }
    }
    return characters;
}

知识点

设置label属性使用attributedText

设置textView属性使用textStorage

回到顶部

三、UIImageView图像处理

contentMode属性,设置图片形状

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIImage *image = [UIImage imageNamed:@"0.png"];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    //设置
    imageView.frame = self.view.frame;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageView];
}

1 代码创建UIImageView,frame默认是图片的大小,.contentMode默认是拉伸,frame如果和图片大小不一致拉伸图片

mode风格

UIViewContentModeScaleToFill,默认拉伸

UIViewContentModeScaleAspectFit, 保持宽高比 ,完全显示,留边

UIViewContentModeScaleAspectFill, 保持宽高比,铺满imageview

Redraw做绘制时使用

UIImageView图片视图控件

* 在界面上的有限空间中显示超过界面大小的内容,(图片,文本)UITextView 是UIScrollView的子类

* 重要属性

.frame -> scrollView在界面上的实际大小和坐标

.contentSize -> scrollView需要显示的内容大小

一般情况下,内容的大小大于frame的大小,以达到滚动效果

注意:这两个属性一定都要设置,否则看不到

* 支持缩放的属性

minimumZoomScale:设置最小的缩放比例

maximumZoomScale:设置最大的缩放比例,一般为1.0

  //水平方向缩放比例

float horizontalScale = scrollView.frame.size.width / self.imageView.frame.size.width;

//垂直方向缩放比例

float vertical = scrollView.frame.size.height / self.imageView.frame.size.height;

//比较水平和垂直方向哪个最小

float minimumZoomScale = MIN(horizontalScale, vertical);

//缩放最小值

scrollView.minimumZoomScale = minimumZoomScale;

//缩放最大值

scrollView.maximumZoomScale = MAX_SCALE;

scrollView.delegate = self;

//scrollview代理中进行缩放的方法,返回一个view进行缩放 按住alt健进行缩放操作

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

return self.imageView;

}

* 其他属性

. showsHorizontalScrollIndicator显示横条

. showsVerticalScrollIndicato 显示竖条

. pagingEnable启动分页控制

. contentInset 内边距

. scrollIndicatorInsets 滚轴的内边距

scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(10, 0, 0, 0);

* 委托协议UIScrollViewDelegate

返回哪一个子视图进行缩放:

缩放开始时调用的方法/结束时调用的方法

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

作业:视力检查表,

Label.font = [UIFont systemFontSize:100];

界面1:label的字体大小是100 E

按钮 看得见 点击进入

界面2:90 E

按钮 看得见 点击进入

界面3:80 E

。。。

看不见显示结果

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.lableE.font = [UIFont systemFontOfSize:100 - self.size2];
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)lookSee:(UIButton *)sender {
    self.size2 += 10;
    MXViewController *viewController = [[MXViewController alloc] initWithNibName:@"MXViewController" bundle:nil];
    viewController.size2 = self.size2;
    [self.navigationController pushViewController:viewController animated:YES];
}
- (IBAction)noLookSee:(UIButton *)sender {
    NSLog(@"看不见了,您的视力是:%d",100 - self.size2);
}

04-UIKit(UINavigationController、NSAttributeString、UIImageView)的更多相关文章

  1. PHP Laravel系列之环境搭建( VirtualBox+Vagrant+Homestead+系列网址)

    搭建环境从来都是阻挡一门新技能的最致命的硬伤,为了这个环境,我又是花费了半天的时间,各种问题层出不穷,下面基于网上的一些教程(我看到的都多少有些问题) 开始的时候是在实验楼这个平台上开始学习的,不过 ...

  2. VMware12安装虚拟机教程、Ubuntu16.04安装教程(包括vmware tools的安装)

    转自https://jingyan.baidu.com/article/c275f6ba07e269e33d756714.html 方法/步骤 1 虚拟机.Linux操作系统介绍及下载地址 虚拟机VM ...

  3. ubuntu16.04系统深度学习开发环境、常用软件环境(如vscode、wine QQ、 360wifi驱动(第三代暂无))搭建相关资料

    事后补充比较全面的(找对资料真的省一半功夫):https://www.jianshu.com/p/5b708817f5d8?from=groupmessage Ubuntu16.04 + 1080Ti ...

  4. MySQL学习笔记(一)Ubuntu16.04中MySQL安装配置(5.6优化、错误日志、DNS解决)

    目录 第一部分.5.6安装.配置.自动备份 第二部分.5.7源码安装.配置.自动备份 第一部分.5.6安装 1.安装mysql sudo apt-get install mysql-server su ...

  5. 美化你的GRUB,全面支持中文(菜单、提示、帮助)适用7.04-9.04

    本文根据网络资料整理而成,在此鸣谢各位作者. 本方法适合 7.04-9.04版本,9.10使用了grub2,请看这里. http://forum.ubuntu.org.cn/viewtopic.php ...

  6. PHP7 学习笔记(一)Ubuntu 16.04 编译安装Nginx-1.10.3、 PHP7.0.9、Redis3.0 扩展、Phalcon3.1 扩展、Swoole1.9.8 扩展、ssh2扩展(全程编译安装)

    ==================== PHP 7.0 编译安装================== wget http://cn2.php.net/get/php-7.0.9.tar.bz2/fr ...

  7. Django 04 模板标签(if、for、url、with、autoeacape、模板继承于引用、静态文件加载)

    Django 04 模板标签(if.for.url.with.autoeacape.模板继承于引用.静态文件加载) 一.if.for.url.with.autoescape urlpatterns = ...

  8. spark 1.6.0 安装与配置(spark1.6.0、Ubuntu14.04、hadoop2.6.0、scala2.10.6、jdk1.7)

    前几天刚着实研究spark,spark安装与配置是入门的关键,本人也是根据网上各位大神的教程,尝试配置,发现版本对应最为关键.现将自己的安装与配置过程介绍如下,如有兴趣的同学可以尝试安装.所谓工欲善其 ...

  9. QTableWidget详解(样式、右键菜单、表头塌陷、多选等) 2013-10-23 10:54:04

    一.设置表单样式 点击(此处)折叠或打开 table_widget->setColumnCount(4); //设置列数 table_widget->horizontalHeader()- ...

随机推荐

  1. BFG

    "/"应用程序中的服务器错误. 配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误消息: 提供程序集合中不 ...

  2. Ext JS学习第三天 我们所熟悉的javascript(二)

    •javascript之函数 •对于Ext开发者,我还是希望你能对javascript原生的东西非常了解.甚至熟练掌握运用.那么函数,无疑是非常重要的概念.首先在前面一讲,我们知道了函数也是一种数据类 ...

  3. PHP开发中常见的安全问题详解和解决方法(如Sql注入、CSRF、Xss、CC等

    页面导航: 首页 → 网络编程 → PHP编程 → php技巧 → 正文内容 PHP安全 PHP开发中常见的安全问题详解和解决方法(如Sql注入.CSRF.Xss.CC等) 作者: 字体:[增加 减小 ...

  4. java之内存可见型

    1.可见性的概念 一个线程对于共享变量的修改,能够及时被其他的线程看到. 2.什么是共享变量 一个变量在多个线程中的工作内存中都存在变量副本,那么这个变量在这几个线程之间共享. 3.Java线程的工作 ...

  5. 《JavaScript权威指南》拾遗(下)

    一.类和原型         1.在JavaScript中,类的实现是基于原型继承机制的,如果两个实例都是从同一个原型对象中继承了属性,则它们是同一个类的实例.         2.原型对象是类的唯一 ...

  6. C# Programming Study #1

    引用的时候需要在参数和使用的时候加上 ref 关键字 static bool addnum (ref int val) //引用 { ++val; return true; } 参数数组的概念,可以接 ...

  7. Subsets 【dfs】

    Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...

  8. 6月10日-IOS应用-日记本

    嗯,经过这几天的学习,我的第一个IOS应用,日记本算是学习完毕了,下面写一篇日记,记录所学到的知识和需要继续学习的地方. 1,首先是ViewController,必须添加两个协议UITableView ...

  9. shell学习之变量、判断、重复动作

    1.1 环境以及变量的定义.赋值.展开.删除 export:将一个变量导入到环境中:export PATH=$PATH:/home. readonly 讲一个变量设置为只读模式,在shell脚本中定义 ...

  10. 转:前端冷知识(~~some fun , some useful)

    前端不为人知的一面——前端冷知识集锦 前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Qu ...