当前位置: 首页 > news >正文

IOS课程笔记[6] 基础控件

UILabel 控件

frame 设置尺寸

    [lb setFrame:CGRectMake(5, 0, 400, 40)];

Font 字体设置

[lb setFont:[UIFont systemFontOfSize:20.f]]    
[lb setFont:[UIFont boldSystemFontOfSize:25.f]];
[lb setFont:[UIFont italicSystemFontOfSize:23.f]];

背景色


[lb setBackgroundColor:[UIColor grayColor]];

shadowColor 阴影设置

设置对齐

//NSTextAlignmentCenter 
//NSTextAlignmentLeft
//NSTextAlignmentRight
[lb setTextAlignment:NSTextAlignmentLeft];

设置行数

//0为自动[lb setNumberOfLines:0]

显示模式


lb.lineBreakMode=NSLineBreakByTruncatingHead;

UIIMageView控件

资源打包

  • 查看调试包路径
// debug模式找到资源位置(lldb) po NSHomeDirectory()/Users/bruce/Library/Developer/CoreSimulator/Devices/78EC5C14-10EA-4BC0-8020-F7668666694D/data/Containers/Data/Application/CE640BE1-3B2A-4AD6-A251-DFE4EB8AC0AA//Containers下的Bundle为沙箱位置/Users/bruce/Library/Developer/CoreSimulator/Devices/78EC5C14-10EA-4BC0-8020-F7668666694D/data/Containers/Bundle/Application/1A2D4A85-1DBB-4134-A958-E9DD5AE1E5D9/BundleMetadata.plist
  • Xcode7以下需要导入文件至Supporting Files中

  • Xcode7以上资源存放在项目配置的Rescources中,如下图

图片添加

//创建图片方式//方式一 通过资源名称UIImage *img2=[UIImage   imageNamed:@"img1"];//方式二 通过文件NSString *path =[[NSBundle mainBundle] pathForResource:@"top/banner" ofType:@"png"];UIImage *img=[UIImage imageWithContentsOfFile:path];

图片模式设置

contentMode的几个属性值:


//可能会被裁剪UIViewContentModeScaleToFill, // 完全缩放UIViewContentModeScaleAspectFit, //按比例缩放UIViewContentModeScaleAspectFill, //按比例填充//重新绘制UIViewContentModeRedraw,//图片偏移UIViewContentModeCenter,UIViewContentModeTop,UIViewContentModeBottom,UIViewContentModeLeft,UIViewContentModeRight,UIViewContentModeTopLeft,UIViewContentModeTopRight,UIViewContentModeBottomLeft,UIViewContentModeBottomRight,

设置尺寸的方式

//创建带尺寸的Image 方式//方式一 直接创建[banner setFrame:CGRectMake(10, 500, 300, 200)];//方式一二 根据图片尺寸创建[banner setFrame:CGRectMake(10, 500, img.size.width, img.size.height)];//方式三  根据尺寸创建UIImageView *banner1=[[UIImageView alloc] initWithFrame:CGRectMake(10, 500, img.size.width, img.size.height)];//方式四 根据图片创建UIImageView *banner2=[[UIImageView alloc] initWithImage:img];banner2.center =CGPointMake(30, 20);

样例


-(void) loadBanner{//创建图片ViewUIImageView *banner=[[UIImageView alloc] init];//设置背景色[banner setBackgroundColor:[UIColor yellowColor]];//设置位置大小 [banner setFrame:CGRectMake(10, 500, 300, 200)];//设置图片UIImage *img=[UIImage   imageNamed:@"img1"];[banner setImage:img];//设置剪裁banner.clipsToBounds=true;//设置 显示模型banner.contentMode=UIViewContentModeScaleToFill;//加毛玻璃UIToolbar *tool= [[UIToolbar alloc] init];// Bounds固定的尺寸,frame可能会随其他设置变化tool.frame =banner.bounds;tool.barStyle = UIBarStyleDefault;tool.alpha =0.6;[banner addSubview:tool];//添加控件[self.view addSubview: banner];}
http://www.lryc.cn/news/204988.html

相关文章:

  • python爬虫入门(五)XPath使用
  • 【广州华锐互动】VR消防员模拟灭火:身临其境的火场救援
  • NFS性能瓶颈分析
  • Java中配置RabbitMQ基本步骤
  • Ingress典型配置
  • webpack中常见的Loader解决了什么问题?
  • 阿里7年经验之谈 —— 如何实现前端项目的自动化测试?
  • 动态开辟内存空间函数
  • nodejs+vue备忘记账系统-计算机毕业设计
  • 百度Comate代码助手SaaS版本:智慧编程,引领新潮
  • 数据与视图的完美契合:Vue响应式的交织魅力
  • Centos8 降低gcc版本至gcc-7.3
  • Qt之设置QLineEdit只能输入浮点数
  • Spark项目实战-卡口流量统计
  • kubernetesr进阶--Secret概述
  • 在 Python 中使用 Pillow 进行图像处理【2/4】
  • XTU-OJ 1171-coins
  • 如何使用 JMeter 进行 HTTPS 请求测试?
  • KNN-水仙花的分类
  • Kotlin 如何确定协程是否启动
  • 【Spring Boot】Spring Boot集成RabbitMQ
  • Hadoop部署过程中问题总结
  • 低成本IC上岸攻略—IC设计网课白嫖篇
  • BootLoader为什么要分阶段?
  • Centos8: 安装python2, 并设置默认版本
  • 【逆向】导入表注入
  • Unity游戏开发中打造游戏攻击技能架构与设计
  • 【微信小程序开发】小程序微信用户授权登录(用户信息手机号)
  • VSCode 自动格式化
  • 数据库、数据仓库相关