製作圖片在右,字在左的 button

iOS 的 UIButton 元件預設的設計是圖片在左,字在右。如下圖所示,當我們設定 image 欄位後,彼得潘的圖片出現在左邊,文字愛瘋一切為蘋果的彼得潘在右邊。

如果我們想和別人不一樣,圖片在右,字在左,可以嗎 ?

當然可以 ! 請從 button 的 Attributes inspector 裡找到 Semantic 欄位。Semantic 是語義的意思,控制著元件內容是由左而右還是由右而左排列。

預設值為 Unspecified,表示內容將依目前使用者手機的語言是由左到右 / 由右到左而調整。

在此我們選擇 Force Right-to-Left,強制它由右而左排列,如此即可實現圖在右,字在左的效果。

不過 storyboard 無法看到效果,你要執行 App 後,才能看到可愛的彼得潘圖案跑到右邊。

)

彼得潘的 iOS App Neverland

Written by

彼得潘的 Swift 程式設計入門,App程式設計入門作者,彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,http://apppeterpan.strikingly.com

彼得潘的 Swift iOS App 開發問題解答集

彼得潘和學生們在開發 iOS App 路上曾經解決的問題集

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade