我收到了错误......
Could not find an overload for 'init' that accepts the supplied arguments
......当我尝试使用......
extension UIFont {
func sizeOfString (string: String, constrainedToWidth width: Double) -> CGSize {
NSString(string).boundingRectWithSize(CGSize(width, DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: [NSFontAttributeName: self],
context: nil).size
}
}
Run Code Online (Sandbox Code Playgroud)
难道NSString不支持这个方法了,还是我的语法搞乱?
我需要根据文本字段的内容增加文本字段的宽度.当用户输入文本时,文本字段大小应自动增加.我在这个文本字段旁边有一个关闭(X)按钮.
我已经约束了文本字段和按钮,以便文本字段在屏幕上居中,并且按钮与它相邻.(文本字段应该是可编辑的,按钮应该是可点击的)
文本字段大小是这样的:
当我在其中输入文本时,大小应自动增加:
我怎样才能做到这一点?
我是Swift的初学者,我正试图获得标签的高度.标签有多行文字.我想知道它在屏幕上占据的总高度.
我遇到了一个问题,我需要动画处理标签垂直翻译textField文本高度的相同距离.在大多数情况下,textField.bounds.heigt但是如果textField的高度大于文本高度,那对我来说就不会有任何好处.所以我需要知道:
如何计算字符串文本的行高UIFont?
关于副本:我需要的东西有点不同.答案(我在答案中引用)得到总高度取决于1)字符串2)宽度3)字体.我需要的是只有字体的一行高度.
我的文字在纵向模式下是两行.当我切换到横向模式时,它适合单行.我通过故事板使用静态tableview单元格; 我怎样才能调整行的大小以适应?
屏幕是一个登录屏幕.
我从这里使用CollapsibleTableView并根据我的要求修改它以实现可折叠部分。这是它现在的样子。
由于根据 UI 设计,我的部分有一个边框,因此我选择了部分标题作为我的 UI 元素,在折叠和展开模式下都保存数据。
原因:我尝试过但无法在下面解释的这个模型中工作 -
** 在部分标题中包含我的标题元素,并在其单元格中包含每个项目的详细信息。默认情况下,该部分处于折叠状态。当用户点击标题时,单元格被切换显示。正如我所说,由于需要向整个部分(点击的标题及其单元格)显示一个边框,因此我选择了部分标题作为我的 UI 操作元素。这是我的 tableView 代码 -
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections.count
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.row {
case 0:
return sections[indexPath.section].collapsed! ? 0 : (100.0 + heightOfLabel2!)
case 1:
return 0
case 2:
return 0
default:
return 0
}
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header …Run Code Online (Sandbox Code Playgroud) 我将我的代码从swift 3.3迁移到4.1而且我收到了这个错误.我怎样才能解决这个问题 ?有什么建议?
progressView.titleLabelAttributedText = NSAttributedString(string: MyxStrings.sharedInstance.SENDING, attributes: [NSFontAttributeName: Scully.sharedInstance.APP_REGULAR_FONT_SMALL!])
Run Code Online (Sandbox Code Playgroud) 我需要确定 uicollectionview 的高度。
let layout = contactCollectionView.collectionViewLayout
let heightSize = String(Int(layout.collectionViewContentSize.height))
Run Code Online (Sandbox Code Playgroud)
上述解决方案适用于我项目中的某些情况。在这种特定情况下,我需要计算行数,然后将其与一个数字相乘以找到高度。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// height = (count rows) * 30 . every cell height is 30
// every cell has different width.
return (presenter?.selectedContact.count)!
}
Run Code Online (Sandbox Code Playgroud)
如何找到行数?
更新
这是我的收藏视图。每个单元格都有不同的宽度(因为它是字符串)。所以它有不同的行。这个collectionView的宽度是view.frame的宽度
swift ×6
ios ×5
autolayout ×1
height ×1
string ×1
swift3 ×1
tableview ×1
uifont ×1
uilabel ×1
uistoryboard ×1
uitableview ×1
uitextfield ×1