- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在使用 UICollectionView 来绘制日历。补充 View 用于表示日历中某一天的列顶部的日期。每个日历都是 UICollectionView 中的一个部分。我们希望突出显示当天。我们的工作方式是
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
var view: UICollectionReusableView?
if kind == WeeklyCollectionElementKindDayColumnHeader {
let dayColumnHeader: WeeklyDayColumnHeader? = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: WeeklyDayColumnHeaderReuseIdentifier, for: indexPath) as? WeeklyDayColumnHeader
let day: Date? = collectionViewCalendarLayout?.dateForDayColumnHeader(at: indexPath)
let currentDay: Date? = currentTimeComponents(for: self.collectionView!, layout: collectionViewCalendarLayout!)
let startOfDay: Date? = Calendar.current.startOfDay(for: day!)
let startOfCurrentDay: Date? = Calendar.current.startOfDay(for: currentDay!)
dayColumnHeader?.day = day
dayColumnHeader?.isCurrentDay = startOfDay == startOfCurrentDay
view = dayColumnHeader
}
else if kind == WeeklyCollectionElementKindTimeRowHeader {
let timeRowHeader: WeeklyTimeRowHeader? = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: WeeklyTimeRowHeaderReuseIdentifier, for: indexPath) as? WeeklyTimeRowHeader
timeRowHeader?.time = collectionViewCalendarLayout?.dateForTimeRowHeader(at: indexPath)
view = timeRowHeader
}
return view!
}
与此
class WeeklyDayColumnHeader: UICollectionReusableView {
var day: Date? {
didSet {
var dateFormatter: DateFormatter?
if dateFormatter == nil {
dateFormatter = DateFormatter()
dateFormatter?.dateFormat = "E d"
}
self.title!.text = dateFormatter?.string(from: day!)
setNeedsLayout()
}
}
var isCurrentDay: Bool = false {
didSet {
if isCurrentDay {
title?.textColor = UIColor.white
title?.font = UIFont.boldSystemFont(ofSize: CGFloat(16.0))
titleBackground?.backgroundColor = UIColor(red:0.99, green:0.22, blue:0.21, alpha:1.0)
}
else {
title?.font = UIFont.systemFont(ofSize: CGFloat(16.0))
title?.textColor = UIColor.black
titleBackground?.backgroundColor = UIColor.clear
}
}
}
设置我们第一次进入这个 View 时想要的背景。但是,如果我打开此 View 并且日期发生变化,如何更新标题?我应该在哪里移动设置日期的逻辑,以及如何“无效”或我需要做的任何事情?
最佳答案
使用UIApplicationSignificantTimeChangeNotification
来通知您时间更改。
使用NotificationCenter
来实现这一点。像这样的事情:
NotificationCenter.defaultCenter().addObserver(self, selector: "dayChanged:", name: UIApplicationSignificantTimeChangeNotification, object: nil)
然后您需要一个函数来处理更改:
func dayChanged(notification: NSNotification){
// trigger the changes you need here
}
关于ios - 如何在 UICollectionView 的 Supplementary View 中触发刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44848418/
所以我有一个 UICollectionView,我想根据用户所处的状态显示多个 UICollectionViewCells 和不同的标题。问题是我似乎无法在 Storyboard中注册多个 UICol
在java.util.Collection的源代码中有一个函数叫做 shuffle : @SuppressWarnings({"rawtypes", "unchecked"}) public stat
我正在使用 Collection View 来显示从 Web 服务获取的数据。我还有一个补充 View (标题),其中包含一个 UIImageView 和一个标签。 UIImageView 通过动画来
我设置了UISplitViewController有风格.tripleColumn . let splitViewController = UISplitViewController(style: .
我们正在使用 UICollectionView 来绘制日历。补充 View 用于表示日历中某一天的列顶部的日期。每个日历都是 UICollectionView 中的一个部分。我们希望突出显示当天。我们
UICollectionView中的装饰和辅助 View 似乎是个大谜团。目前似乎几乎没有示例代码。我设法让这两种类型在自定义布局中工作(有关详细信息,请参阅此 post)。只要它们保持在同一位置,一
我正在为图标使用网络字体。图标字形映射到 Unicode 的补充专用区 A 和 B。 如果我通过 data-* 属性将字符传递到 CSS,一切正常: 然后: .icon::before {
我是一名优秀的程序员,十分优秀!