首页 文章 精选 留言 我的

精选列表

搜索[网站开发],共10000篇文章
优秀的个人博客,低调大师

Android开发七 Android中的显示单位

px (pixels)像素 一般HVGA代表320x480像素,这个用的比较多。 dip或dp (device independent pixels)设备独立像素 这个和设备硬件有关,一般为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。 sp (scaled pixels — best for text size)比例像素 主要处理字体的大小,可以根据系统的字体自适应。 除了上面三个显示单位,下面还有几个不太常用: in (inches)英寸 mm (millimeters)毫米 pt (points)点,1/72英寸 为了适应不同分辨率,不同的像素密度,推荐使用dip ,文字使用sp。 本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2012/04/01/2428999.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-适配器和外观模式

适配器模式,属于结构型模式,其主要作用是将一个类的接口转换成客户希望的另外一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。适配器模式有对象适配器和类适配器两种,类适配器模式需要语言实现多继承,OC不支持多继承,所以一般我们都实现对象适配器。外观模式提供了一个统一的接口,用来访问子系统中的一群接口,外观定义了一个高层接口,让子系统更容易使用。适配器是为了转换接口,外观模式是为了简化接口。 适配器模式 对象适配器模式UML类图: 关于适配模式最常见的就是手机充电的例子,通过数据线和转换口连接,然后将转换口和插座连接,转换口就可以理解为适配器~ 数据线(Target): 1 2 3 4 5 6 7 8 9 10 11 @protocol DataLineProtocol <NSObject> @optional -( void )connect; @end @ interface DataLine : NSObject<DataLineProtocol> @end 电源插头(Adapter): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 @ interface DataAdapter(){ EleSocket *eleSocket; } @end @implementation DataAdapter -(instancetype)initWithEleSocket:(EleSocket *)socket{ self=[super init]; if (self) { eleSocket=socket; } return self; } -( void )connect{ [eleSocket speicalConnect]; } @end 被适配者(插座): 1 2 3 4 5 6 7 @implementation EleSocket -( void )speicalConnect{ NSLog( @"specialConnect--电源接通" ); } @end 客户端(手机): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 @ interface Mobile(){ DataLine *dataLine; } @end @implementation Mobile -(instancetype)initWithDataLine:(DataLine *)line{ self=[super init]; if (self) { dataLine=line; } return self; } -( void )charge{ [dataLine connect]; } @end 客户端调用: 1 2 3 4 EleSocket *socket=[[EleSocket alloc]init]; DataLine *line=[[DataAdapter alloc] initWithEleSocket:socket]; Mobile *moblie=[[Mobile alloc]initWithDataLine:line]; [moblie charge]; 测试结果: 外观模式 外观模式通过引入一个外观角色来简化客户端与子系统之间的交互,为复杂的子系统调用提供一个统一的入口,降低子系统与客户端的耦合度,且客户端调用非常方便。适配器是是接口转换,外观是简化接口,将多个子系统接口转换为一个,最简单的例子就是在饭店吃饭和在家吃饭,如果去饭店吃饭,只需要下单,等个十几二十分钟我们就可以吃饭,在家自己做饭就需要买菜,淘米,炒菜等等一系列动作。 UML类图: 我们简单的模拟一下餐馆点餐的过程需要饭店,服务员,厨师: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 @ interface Hotel(){ Waiter *myWaiter; Cook *myCook; } @end @implementation Hotel -(instancetype)initWithCook:(Waiter *)waiter cook:(Cook *)cook{ self=[super init]; if (self) { myWaiter=waiter; myCook=cook; } return self; } -( void )order{ [myWaiter handleOrder]; [myCook cook]; [myCook complete]; } @end 客户端调用: 1 2 Hotel *hotel=[[Hotel alloc]initWithCook:[Waiter new ] cook:[Cook new ]]; [hotel order]; 关于门面模式的简单实现中我们通过一个接口,可以调用子系统的接口,非常简单,外观模式的优势有以下几点: ①对客户屏蔽子系统组件,减少了客户处理的对象数目并使得子系统使用起来更加容易。通过引入外观模式,客户代码将变得很简单,与之关联的对象也很少。 ②实现了子系统与客户之间的松耦合关系,这使得子系统的组件变化不会影响到调用它的客户类,只需要调整外观类即可。 ③ 降低了大型软件系统中的编译依赖性,并简化了系统在不同平台之间的移植过程,因为编译一个子系统一般不需要编译所有其他的子系统。一个子系统的修改对其他子系统没有任何影响,而且子系统内部变化也不会影响到外观对象。 ④提供了一个访问子系统的统一入口,并不影响用户直接使用子系统类。 外观模式的缺点: ① 不能很好地限制客户使用子系统类,如果对客户访问子系统类做太多的限制则减少了可变性和灵活性。 ② 在不引入抽象外观类的情况下,增加新的子系统可能需要修改外观类或客户端的源代码,违背了“开闭原则”。 本文的子系统对象可以从外部传递,如果不希望从外部传递,可以在初始化的时候内部对子系统的进行初始化~ 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/5123168.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-VFL(Visual format language)和Autolayout

AutoLayout不管是在StoryBorad还是在xib中都相对来说比较简单,VFL(Visual fromat language)可视化语言基本上用到的比较少,在xCode4时候自动布局的概念还没有,直接使用VFL会很方便,可视化语言依赖于oc运行时创建对应的约束,如果IBOutlet发生改变有的时候会造成莫名其妙的Bug。xCode5之后可视化语言用到的场景相对较少,但是作为一个工作的辅助还是可以稍微了解下。 基础知识 在StotyBoard中添加一个标签一个按钮,不适用自动布局,简单的控制它们之间的水平距离为80,如下图所示: 视图中添加约束: 1 2 NSLayoutConstraint *labelContraint=[ NSLayoutConstraint constraintWithItem: self .changeButton attribute: NSLayoutAttributeLeft relatedBy: NSLayoutRelationEqual toItem: self .descriptionLabel attribute: NSLayoutAttributeRight multiplier:1.0 constant:60]; [ self .view addConstraint:labelContraint]; 这个只是视图约束的一种方式,下面这种方式才是本文的主角: 1 2 3 4 //使用可视化语言添加约束 NSDictionary *viewDictionary= NSDictionaryOfVariableBindings (_descriptionLabel,_changeButton); NSArray *visualConstraint=[ NSLayoutConstraint constraintsWithVisualFormat:@ "[_descriptionLabel]-60-[_changeButton]" options:0 metrics: nil views:viewDictionary]; [ self .view addConstraints:visualConstraint]; 这里面用到的constraintsWithVisualFormat方法,具体参数说明如下: format:参数是vfl语句,语句的基本元素下面会详细解释一下; opts:枚举参数,默认写0; metrics:字典,当在format中使用了动态数据,会根据字典去匹配,接下来会具体有例子; views:字典,传入需要用到的视图集合; 具体format需要参考一下表达式的意思: 水平方向 H: 垂直方向 V: Views [需要定义的视图] SuperView | 关系 >=,==,<= 间隙 - 视图内部约束 () Demo实战 通过VFL控制手动添加的标签的位置,具体效果如下: 代码实现如下: 1 2 3 4 5 6 7 8 9 10 11 UILabel *link=[[UILabel alloc]init]; link.text=@ "http://www.cnblogs.com/xiaofeixiang" ; link.translatesAutoresizingMaskIntoConstraints= NO ; [link setBackgroundColor:[UIColor greenColor]]; [ self .view addSubview:link]; NSArray *horizontal=[ NSLayoutConstraint constraintsWithVisualFormat:@ "H:|-40-[link]-20-|" options:0 metrics: nil views: NSDictionaryOfVariableBindings (link)]; NSArray *vertical=[ NSLayoutConstraint constraintsWithVisualFormat:@ "V:[_descriptionLabel]-100-[link(>=30)]" options:0 metrics: nil views: NSDictionaryOfVariableBindings (link,_descriptionLabel)]; [ self .view addConstraints:horizontal]; [ self .view addConstraints:vertical]; 第一个约束是控制标签距离父视图左右之间的距离,第二个控制标签和”博客园-FlyElephant"之间的垂直距离为100.当然如果你想通过字典控制垂直之间的距离可以按照下面这么做: 1 NSArray *vertical=[ NSLayoutConstraint constraintsWithVisualFormat:@ "V:[_descriptionLabel]-Vertical-[link(>=30)]" options:0 metrics:@{@ "Vertical" : @200 } views: NSDictionaryOfVariableBindings (link,_descriptionLabel)]; 最后的结果: 友情提示在添加约束的时候不要和StoryBoard中的冲突,如果添加的水平约束StoryBoard中也有的话,就会出现下面这种情况: 1 2 3 4 5 6 7 8 9 10 11 12 2015-07-01 10:54:13.537 VFLDemo[2358:60863] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don 't want. Try this: (1) look at each constraint and try to figure out which you don' t expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you 're seeing NSAutoresizingMaskLayoutConstraints that you don' t understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSLayoutConstraint:0x7fc5e3732860 H:[UILabel:0x7fc5e372ef30'\U535a\U5ba2\U56ed-FlyElephant']-(15)-[UIButton:0x7fc5e372d550'\U7fa4:228407086']>" , "<NSLayoutConstraint:0x7fc5e37344e0 H:[UILabel:0x7fc5e372ef30'\U535a\U5ba2\U56ed-FlyElephant']-(60)-[UIButton:0x7fc5e372d550'\U7fa4:228407086']>" ) Will attempt to recover by breaking constraint < NSLayoutConstraint :0x7fc5e37344e0 H:[UILabel:0x7fc5e372ef30 '博客园-FlyElephant' ]-(60)-[UIButton:0x7fc5e372d550 '群:228407086' ]> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4612683.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册