changjiashuai's blog

Runnig...

The future belongs to those who believe in the beauty of their dreams.


自动布局

AutoLayout是一种基于约束的,描述性的布局系统。

  item1.attribute1 = multiplier * item2.attribute2 + constant

  + (id)constraintWithItem:(id)item1
                 attribute:(NSLayoutAttribute)attribute1
                 relatedBy:(NsLayoutRelation)relation
                    toItem:(id)item2
                 attribute:(NSLayoutAttribute)attribute2
                multiplier:(CGFloat)multiplier
                  constant:(CGFloat)constant;

  Button.centerX = Superview.centerX
  // =>
  [NSLayoutConstraint constraintWithItem:button
                 attribute:NSLayoutAttributeCenterX
                 relatedBy:NsLayoutRelationEqual
                    toItem:superview
                 attribute:NSLayoutAttributeCenterX
                multiplier:1.0
                  constant:0.0];

  Button.bottom = Superview.bottom - <padding>
  // =>
  [NSLayoutConstraint constraintWithItem:button
                 attribute:NSLayoutAttributeBottom
                 relatedBy:NsLayoutRelationEqual
                    toItem:superview
                 attribute:NSLayoutAttributeBottom
                multiplier:1.0
                  constant:-padding];

Visual Format Syntax

1. Standard Space

  [button]-[textField]

2. Width Constraint

  [button(>=50)]

3. Connection to Superview

  |-50-[purpleBox]-50-|

4. Vertical Layout

  V:[topField]-10-[bottomField]

5. Flush Views

  [maroonView][blueView]

6. Priority

  [button(100@20)]

7. Equal Widths

  [button1(==button2)]

8. Multiple Predicates

  [flexibleButton(>=70,<=100)]

9. A Complete Line of Layout

  |-[find]-[findNext]-[findField(>=20)]-|


链接

最近的文章

Django实践:自定义用户系统

扩展Django的用户系统有几个方法: 1.在自定义Model中使用OneToOneField的方式来扩展,实现一个User Profile。这种方式在1.5之前是推荐的,在User也有一个默认的get_profile方法来获取这个profile。这种方式的好处是1.5以前的版本默认支持,并且对Django的影响最小,坏处主要是获取资料的时候需要一次join表。示例代码如下: class UserProfile(models.Model): user = models...…

继续阅读
更早的文章

Eclipse工程导入到Android Studio

1、首先升级ADT到最新版本 2、选择需要从Eclipse导出的工程,右键选择Export并选择Android下的Generate Gradle Build Files 如图所示: 3、选择完毕后并不会导出到其他地方,而是在本地工程生成一个build.gradle文件,在Eclipse工程中也可以看到,这个文件是Android Studio识别的,如图所示: 4、随后进入Android Studio并选择Import Project,可以看到刚刚在Ecli...…

继续阅读