This is my first time to ask a question after I just started programming, so please forgive me if there is anything that doesn't work out.
Using the Xcode storyboard, I'm trying to create an arrangement with four buttons arranged vertically.
I filled the title of the button to the left so that the right end of the title (the red circle on the first picture) is aligned with the right end of the title of the other button, but it didn't fit very well.
Please let me know if there is a way to get this right on any model.
The button settings are as shown in the second picture.
In addition to this, I use the code Button.titleLabel?.adjustsFontSizeToFitWidth=true
to display it as large as possible.
I tried to arrange it by changing the size of the half-width space, but only one model would be available, but not the other.
display examples:
button settings:
swift xcode storyboard
First, I would like to point out that controls responding to user taps are not necessarily limited to buttons (UIButton
).I have to write a little complicated code, but if I were to create an interface that the questioner wanted to create, I would consider using a table (UITableView
) and each cell would consist of a left-packed text label ("arrow", "two U-magnets", etc.) and a right-packed label ("1500", "100000", etc.).
Second, if you intend to use a half-width space so that the right end of the title (the red circle part of the first image) aligns with the right end of the title of the other button, you should use an equal width font."Equivalent width" means that the width of the body of each character is equal.There are two types of spaces, full-width characters, such as kanji and kana, and half-width characters, such as alphanumeric characters, but full-width characters are twice the size of half-width characters, so you can adjust the length of each line.
import UIKit
classViewController:UIViewController {
@IBOutlet weak var button 1: UIButton!
@IBOutlet weak var button 2: UIButton!
override func viewDidLoad(){
super.viewDidLoad()
button1.titleLabel?.font=UIFont.monospacedSystemFont (ofSize:17, weight:.regular)
button2.titleLabel?.font=UIFont.monospacedSystemFont (ofSize:17, weight:.regular)
}
}
In UIKit
, use class func monospacedSystemFont(ofSize fontSize:CGFloat, weight:UIFont.Weight) ->UIFont
to specify equal width fonts.
Third, I don't understand why the questioner designates MSP Gothic fonts that are not installed on macOS or iOS as standard on the Storyboard."P" in "MSP Gothic" means "propotic", and not only alphanumeric characters, but also hiragana and katakana are fonts with different widths depending on the characters.As you can see from the image presented by the questioner, the width is different between the three kanji characters of peanuts and the three kana characters of apples, right?
You should not use fonts that are not equal in width when you use space to align line lengths.
In addition, fonts that are not installed normally on iOS will be replaced by other fonts on devices that are not installed (iPhone).That's why the result is, "If only one model is available, it will be available, but the other model is not available."
In principle, only system-standard fonts should be used unless fonts are included in the app.
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.