Xib 上面可以添加輔助線,有時(shí)候善加使用,可以起到事半功倍的效果。

輔助線.png
1. 如何添加輔助線
點(diǎn)擊Xib,選中最右側(cè)的View控件讓其處于選中狀態(tài)。然后點(diǎn)擊Editor->Guides 這時(shí)候,點(diǎn)擊右側(cè)出現(xiàn)的 Add Horizontal Guide 和 Add Vertical Guide 就可以添加上了。

添加輔助線.png
- 每一條添加的輔助線初始都是水平居中或者垂直居中的,可以添加多條。
- 每條輔助線都可以任意移動(dòng)其位置,移動(dòng)時(shí)輔助線上下或左右會(huì)出現(xiàn)2個(gè)數(shù)字,對(duì)應(yīng)的表示輔助線離上下或左右的邊框的距離。
- 輔助線這貨感覺就相當(dāng)于槍的準(zhǔn)心,對(duì)View上面的控件的位置進(jìn)行校準(zhǔn)對(duì)齊,如果你練成了傳說中的“像素眼”,輔助線對(duì)你來說基本就沒什么用了。
2. 如何刪除輔助線
前段時(shí)間,有位同道之人問到,怎么刪除Xib上的的輔助線?我覺得有添加的按鈕就應(yīng)該有刪除的方法(毒蛇出沒之處七步之內(nèi)必有解藥?)。
找了一會(huì)發(fā)現(xiàn),明面上是真沒有看到(大概是蘋果覺得添加了多條之后,不知道你要?jiǎng)h除全部還是多條或是某一條,刪除做起來麻煩就沒做,而且輔助線過于細(xì)小,不好選中,delete也就無效了。)。但是暗地里還是找到一種刪除的方法。
首先,找到對(duì)應(yīng)的Xib文件,選中以后右鍵點(diǎn)擊 Open As --> Source Code
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ViewController3">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<userGuides>
<userLayoutGuide location="284" affinity="minY"/>
<userLayoutGuide location="284" affinity="minY"/>
<userLayoutGuide location="160" affinity="minX"/>
</userGuides>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<point key="canvasLocation" x="245" y="385"/>
</view>
</objects>
</document>
打開以后,搜索userGuides然后把帶userGuides標(biāo)簽的一整塊都刪除。
<userGuides>
<userLayoutGuide location="284" affinity="minY"/>
<userLayoutGuide location="284" affinity="minY"/>
<userLayoutGuide location="160" affinity="minX"/>
</userGuides>
然后,找到對(duì)應(yīng)的Xib文件,選中以后右鍵點(diǎn)擊 Open As --> interface Builder XIB Document 還原為Xib文件,就可以看到所有輔助線都不辭而別了。