- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我成功地将支票号码作为文本添加到 pickerView。但我希望用于删除线的支票号码的文本。可以将标签文本更改为删除线的代码不适用于 pickerView 中的项目。您会在 pickerView 中看到类似“1023 { 这是删除线 }” 的内容。是否有同时具有删除线和普通字符的字体?有任何想法吗?
最佳答案
所以看起来您需要为选择器 View 使用 NSAttributedString 对象。
和it looks like the only solution you might have available to you就是使用UIPickerViewDelegate方法pickerView:viewForRow:forComponent:reusingView:
.
如果您实现该方法,您将返回一个 UIView 对象,您可以在其中拥有一个使用属性字符串的 UILabel。
如果这是我的问题,我可能会这样做:
func pickerView(_ pickerView: UIPickerView,
viewForRow row: Int,
forComponent component: Int,
reusingView view: UIView?) -> UIView
{
// create a mutable attributed string
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "Your String here")
// add strikethrough attribute to the whole string
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length))
// set up a label
let pickerLabel = UILabel(frame: CGRectMake(0, 0, 200, 21))
pickerLabel.center = CGPointMake(160, 284)
pickerLabel.textAlignment = NSTextAlignment.Center
// and set the contents to the atributedString
pickerLabel.attributedText = attributeString
return pickerLabel
}
关于swift - 在 Swift 中将 pickerView 中的文本设为删除线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35908467/
我在一个 View Controller 上使用多个pickerview。我在相应的选取器 View 中获得正确的数据,但选取器 View 中的行对称 View 不正确。第一个选择器 View 中的数
我在 View 中有多个文本字段,其中输入 View 设置为 pickerView,但是根据文本字段,应该显示不同数量的选择行。当您单击选取器 View 外部,然后单击下一个文本字段时,此方法工作正常
我有两个 pickerView,即 pickerView1 = car_make、pickerView2 = car_model。 如果我选择 car_make = Kia,我希望 pickerVie
我创建了一个使用数组作为数据源的 UIPickerView,我想在第三个组件上选择一个项目后隐藏第四个组件上的一些项目。我该怎么做? class ViewControllerEspessuras: U
我尝试使用此方法selectedRow(inComponent: 0),但它对我不起作用。当选择器不活动时,有什么方法可以从选择器中获取第一个/默认值吗? func pickerView(_ pick
我一直在寻找答案,但找不到任何明确的解决方案。我正在制作一个具有三个具有相同 UIpickerViews 的 UItextFields 的 View Controller 。如果已在另一个 UItex
UIPickerView 显示数据,但不会传输到 UITextField。 我检查了其他帖子来比较我的代码,仍然找不到解决方案。非常感谢您的帮助。 import UIKit class ViewCon
当我尝试对 pickerView 中的特定行执行操作时,我遇到了一个问题。 例如,我在 pickerView 中有多个项目,而在核心数据中我有计数器属性,所以我需要做的是,一旦我从 pickerVie
我在现有应用程序中有一个使用小数位的自定义键盘。我正在尝试实现英制测量。 所以我从键盘上删除了小数点,并添加了一个选择器 View ,我希望在其中包含 1/32 -> 31/32 之间的所有可能的分数
当我点击文本字段时,会出现输入区域,但只有 1 行,内容为空白。 (我期望 3 行:a、b 和 c) 我将 numberOfRowsInComponent 和 titleForRow 函数中的返回值更
我正在尝试制作一个 pickerView,用户可以在其中选择他/她的体重...在 Swift 2.2 中,我正在考虑制作这样的 Range: var weightList: [Int] = Array
我是 iOS 新手。谁能帮助我如何使用 PickerView 来显示年份和月份?如何设置每列的大小? - (NSInteger)numberOfComponentsInPickerView:(UIPi
我使用 inputView 在单击文本字段时显示 pickerView。然后我想用数字 1-100 填充 pickerview。我有一些我认为可以工作的代码,但是当我运行程序并单击文本字段时,它只会弹
我制作了一个字体选择器,可以显示轮子内的所有字体。 我现在需要添加 2 个额外的部分来更改字体大小和样式(粗体、斜体、下划线)。 样式和大小是 UIFont 类的成员吗?如果是这样,如何访问它们? 这
这是我的代码: @synthesize pickerLetter, pickerNumber, pickerSymbol; - (void)viewDidLoad { [super viewDidL
我想要做的是根据从选择器中选择的内容显示特定的文本字符串。例如,可以在选择器中选择蓝色、绿色和黄色选项。当您选择蓝色时,一些文本(例如,我喜欢海洋!)会输出到标签。 我已经一切正常,除了在选择器中选择
我试图调出一个选择器 View 而不是键盘来放入文本字段,但我的选择器 View 没有显示。 #import "SettingsViewController.h" #import "FindCla
我正在从一个 JSON 文件中解析一些数据 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"airports" ofType
我正在尝试获取其中包含数字列表的选择器 View 。 到目前为止,我可以获得包含所有数字的字符串,但是当将其放入选择器 View 时,选择器 View 始终为空。你能看看我的代码,让我知道哪里出错了吗
我使用了一个带有四个组件的 UIPickerView 来在没有键盘的情况下输入数字。我添加了一个小数点,只有一个“。”在 UILabelView 中。查看屏幕了解想法。 我的 UIPickerView
我是一名优秀的程序员,十分优秀!