- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 UIViewController
中,有一个位于 View 顶部的分段 Controller 。约束:左:0,右:0,上:0,高:90。
每次发布 UIApplicationDidBecomeActive
通知时,分段控件应通过调用 func updateUI()
以最新日期更新它的 View
在第一次加载时,当 viewDidLoad
被调用时,每个段中的文本都按预期显示。
但是,如果应用程序进入后台,当它返回前台时,分段控件的标签不容纳文本并显示 3 个点...之后。请参阅下面的附件和 gif。
范围:每次发布 .UIApplicationDidBecomeActive
通知时更新每个段的分段控件标题。 公共(public) Github 项目 https://github.com/bibscy/testProject
class ViewController: UIViewController {
var stringDates = [String]()
var dateNow: Date {
return Date()
}
@IBOutlet weak var segmentedControl: UISegmentedControl!
func updateUI() {
//create string dates and set the title of for each segment in segmented control
self.getNextDays()
}
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: .UIApplicationDidBecomeActive, object: nil)
UILabel.appearance(whenContainedInInstancesOf: [UISegmentedControl.self]).numberOfLines = 0
self.getNextDays()
}
}
extension ViewController {
//for each segment, construct a string date with the currentDate() being first, followed by 5 consecutive days
func getNextDays() {
stringDates.removeAll() //clear any previous data
for i in 0...5 {
let dateFormatter = DateFormatter()
let today = dateNow
let calendar = Calendar.current
if i == 0 {
let dayComponent = Calendar.current.component(.weekday,from: today)
let day = Calendar.current.component(.day, from: today) //Int
let dayString = dateFormatter.shortWeekdaySymbols[dayComponent-1] //Symbol
let month = Calendar.current.component(.month, from: today)
let monthSymbol = dateFormatter.shortMonthSymbols[month-1]
let dayMonthString = dayString + " " + String(day) + " " + monthSymbol
stringDates.append(dayMonthString)
} else {
var components = DateComponents()
components.weekday = i
let nextDay = calendar.date(byAdding: components, to: today)
let nextDayComponent = Calendar.current.component(.weekday,from: nextDay!)
let day = Calendar.current.component(.day, from: nextDay!)
let dayString = dateFormatter.shortWeekdaySymbols[nextDayComponent-1] // Symbol
let month = Calendar.current.component(.month, from: nextDay!)
let monthSymbol = dateFormatter.shortMonthSymbols[month-1]
let dayMonthString = dayString + " " + String(day) + " " + monthSymbol
stringDates.append(dayMonthString)
}
}
//set the title for each segment from stringDates array
for value in 0...5 {
self.segmentedControl.setTitle(self.stringDates[value], forSegmentAt: value)
}
} //end of getNextDays()
}
最佳答案
该问题仅在 10.3 iOS 版本中重现。解决方案:
存储分段标签的初始属性:
fileprivate var height: CGFloat!
fileprivate var width: CGFloat!
在 getNextDays
之前添加到 ViewDidLoad:
let label = segmentedControl.subviews[0].subviews[0] as! UILabel
height = label.frame.height
width = label.frame.width
设置文本:
for value in 0...5 {
segmentedControl.setTitle(stringDates[value], forSegmentAt: value)
}
然后修复框架:
let labels = segmentedControl.subviews.map{ $0.subviews[1] } as! [UILabel]
labels.forEach { (label) in
label.numberOfLines = 0
let frame = label.frame
label.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: width, height: height)
}
关于ios - 如何在 Swift 的分段控件中调整 textLabel 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50579137/
最近,我读了一本名为Understanding the linux kernel 的书。有一句话让我很困惑。谁能给我解释一下? As stated earlier, the Current Privi
Julia中是否有任何类型的分段/非连续范围的对象类?例如,我可以创建一个常规范围: a = UnitRange(1:5) 但是,如果我想将此与其他范围相结合: b = UnitRange([1:5,
我一直在研究标准输入的修复后计算器,在研究它之后,我最终得到了一个说法“段错误(核心转储)”,它没有说明它发生的位置或导致它的原因,并在寻找解释后我真的找不到任何可以帮助我解决这个问题的东西。所以我决
我对创建应用程序还很陌生,我刚开始使用 Swift 进行 iOS 开发。我真的希望有人能花点时间帮助我,因为我现在很困。所以我正在创建一个带有主从 TableView 的应用程序。我将使用 Alamo
ScrollView 或类似的东西中的 UIView、SegmentedController 和 UIContainerView? 在我的 Storyboard中,我有一个 VC,它在顶部包含一个 U
我需要构建一个具有任意数量的间隔和函数的分段函数,能够对输入的 numpy 数组进行操作。 我可以使用 for 循环和指示符数组来做到这一点,如下面的代码片段所示,但是有没有一种更 Pythonic
我正在尝试按照提交的方式输出我的输出,但它不起作用。比如说,如果我提交一个分为两段的帖子(通过按回车键将它们分开)它不会那样输出。它删除该段落并将帖子显示为一个段落。 显示结果: 我正在尝试按照提交的
我有一个 TableView Controller ,其中按字母顺序列出了美国所有州。单击某个状态会通过 Web 服务调用返回有关该状态的详细信息。这是我第一次尝试分段或分组 TableView ,我
我想创建一个链接节点列表。这个想法是用字母分隔一个单词,并通过每个不同的字母创建一个链接节点列表。我也尝试在最后一个位置添加最后一个节点。 我已经尝试了很多东西,理论上是可行的,但我找不到段错误的根源
这是我正在尝试创建的附加组件: import bpy import os import sys import subprocess import time from threading import
我觉得这应该是一个简单的属性,但我一直在搜索,但找不到答案。 我的表右侧有一个 TableView 索引。选择后,它会使所有内容变灰。我想模仿 iPod 应用程序,当索引本身被选中时,它是半透明的(可
我试图在 OpenCV 中使用 SLIC 分割图像。我正在尝试使用以下功能: void vl_slic_segment ( vl_uint32 * segmentation, flo
我知道在网络中,数据流在第4层被分成不同的段。每个段然后用端口号和IP地址封装。我发现了一些我想问的令人困惑的问题: 谁负责将数据流分成不同的段。是应用程序还是第 4 层? 我知道 UDP 不支持分段
我有一个使用界面生成器制作的分段 Controller ,它看起来像这样 有时我使用它将它设置为四个 [segmentedControl insertSegmentWithTitle:@"Dinner
所以我使用免费托管,我的服务器上几乎没有视频,一切正常,除了视频需要大约 10-20 秒来加载然后开始播放,所以我想使用流媒体。问题是我不知道该字段和托管不支持 node.js,但我认为是 php 7
ViewController 有三个按钮:“ friend ”“日历”“信息”。每个按钮将代表此 viewController 下半部分的不同信息。 我的问题是选择什么来表示这些信息 - 分段 Con
在我的应用程序中,弹出窗口中的 UITableView 会在新数据时重新加载。如果表格未分区,则使用此代码一切都可以完美运行: 通知,启动重新加载: - (void)recieveNotificati
在阅读muduo(C++网络库)的源码时提出了这个问题。 如果客户端发送一个大消息,它将被 TCP 分段,服务器端会发生什么? (服务器是否知道这条消息已经被分段了?) 网络库是否需要等待整个消息并且
我正在重构一个包含大量长头文件的代码库(为了便于使用和简化编译,头文件同时包含接口(interface)和实现)。 代码库避免了像野火一样的多态性,因此它使用宏解析内部存储类型,如下所示: #if d
我正在阅读有关 x86 保护模式工作的信息,因为我已经看到了平面内存模型和分段内存模型。 如果 linux 内核使用平面内存模型,那么它如何保护非特权应用程序对关键数据的访问? 最佳答案 Linux
我是一名优秀的程序员,十分优秀!