一个使用 Swift 编写的简单 macOS 带标签文本框。
将 https://github.com/dagronf/DSFLabelledTextField
添加到您的项目中。
将以下内容添加到您的 Podfiles
文件中
pod 'DSFLabelledTextField', :git => 'https://github.com/dagronf/DSFLabelledTextField'
将 Sources/DSFLabelledTextField
子文件夹中的 Swift 文件添加到您的项目中
DSFLabelledTextField
,或者drawsRoundedEdges
: 使用圆角矩形绘制控件边框drawsLabelBackground
: 在标签后面绘制纯色背景label
: 要在标签中显示的文本labelForegroundColor
: 标签文本的颜色labelBackgroundColor
: 标签后面的颜色labelWidth
: 标签的宽度。如果设置为 -1,则使标签大小适应标签文本。labelAlignment
: 标签的对齐方式。如果您有多个需要同步宽度的标签字段,则此选项非常有用。默认为 NSTextAlignment.center
有时您可能需要同步多个字段的标签宽度。 为此,您可以将这些字段添加到 DSFLabelledTextFieldGroup
实例,字段标签将调整大小以适应组中所有标签的最大宽度。
@IBOutlet weak var redField: DSFLabelledTextField!
@IBOutlet weak var greenField: DSFLabelledTextField!
@IBOutlet weak var blueField: DSFLabelledTextField!
let colorGroup = DSFLabelledTextFieldGroup()
override func viewDidLoad() {
super.viewDidLoad()
/// Sync the widths of the red, green and blue labels
self.colorGroup.add(fields: redField, greenField, blueField)
}
1.2.0
: 修复了 @IBInspectable
未出现在 Interface Builder 中的问题。更好地显示“已启用”状态。1.1.0
: 增加了对标签分组的支持1.0.2
: 增加了标签对齐方式(左对齐、右对齐、居中等)1.0.1
: 演示动态创建1.0.0
: 初始版本MIT License
Copyright (c) 2020 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.