@ -67,7 +67,7 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
private let showAllMediaButton : Bool
private let sliderEnabled : Bool
private let headerView : UI Stack View
private let headerView : UI View
init ( initialItem : MediaGalleryItem , mediaGalleryDataSource : MediaGalleryDataSource , uiDatabaseConnection : YapDatabaseConnection , options : MediaGalleryOption ) {
assert ( uiDatabaseConnection . isInLongLivedReadTransaction ( ) )
@ -78,20 +78,29 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
let kSpacingBetweenItems : CGFloat = 20
let headerView = UIStack View( )
self . headerView = headerView
self . headerView = UI View( )
headerView . layoutMargins = UIEdgeInsets ( top : 2 , left : 8 , bottom : 4 , right : 8 )
super . init ( transitionStyle : . scroll ,
navigationOrientation : . horizontal ,
options : [ UIPageViewControllerOptionInterPageSpacingKey : kSpacingBetweenItems ] )
// n e e d e d f o r p r o p e r l a y o u t o n i O S 9 / 1 0
headerView . translatesAutoresizingMaskIntoConstraints = false
let headerStackView = UIStackView ( )
headerView . addSubview( headerStackView )
headerView . axis = . vertical
headerView . alignment = . center
headerView . addArrangedSubview ( headerNameLabel )
headerView . addArrangedSubview ( headerDateLabel )
headerStackView . axis = . vertical
headerStackView . alignment = . center
headerStackView . spacing = 0
headerStackView . distribution = . fillProportionally
headerStackView . addArrangedSubview ( headerNameLabel )
headerStackView . addArrangedSubview ( headerDateLabel )
headerStackView . autoPinEdge ( toSuperviewMargin : . top , relation : . greaterThanOrEqual )
headerStackView . autoPinEdge ( toSuperviewMargin : . right , relation : . greaterThanOrEqual )
headerStackView . autoPinEdge ( toSuperviewMargin : . bottom , relation : . greaterThanOrEqual )
headerStackView . autoPinEdge ( toSuperviewMargin : . left , relation : . greaterThanOrEqual )
headerStackView . setContentHuggingHigh ( )
headerStackView . autoCenterInSuperview ( )
self . dataSource = self
self . delegate = self
@ -589,6 +598,7 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
label . font = UIFont . ows_regularFont ( withSize : 12 )
label . textAlignment = . center
label . adjustsFontSizeToFitWidth = true
label . minimumScaleFactor = 0.8
return label
} ( )
@ -609,5 +619,19 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
let date = Date ( timeIntervalSince1970 : Double ( item . message . timestamp ) / 1000 )
let formattedDate = dateFormatter . string ( from : date )
headerDateLabel . text = formattedDate
if #available ( iOS 11 , * ) {
// D o n o t h i n g , o n i O S 1 1 , a u t o l a y o u t g r o w s t h e s t a c k v i e w a s n e c e s s a r y .
} else {
// S i z e t h e t i t l e V i e w t o b e l a r g e e n o u g h t o f i t t h e w i d e s t l a b e l ,
// b u t n o l a r g e r . I f w e g o f o r a " f u l l w i d t h " l a b e l , o u r t i t l e v i e w
// w i l l n o t b e c e n t e r e d ( s i n c e t h e l e f t a n d r i g h t b a r b u t t o n s h a v e d i f f e r e n t w i d t h s )
headerNameLabel . sizeToFit ( )
headerDateLabel . sizeToFit ( )
let maxWidth = max ( headerNameLabel . frame . width , headerDateLabel . frame . width )
let headerFrame : CGRect = CGRect ( x : 0 , y : 0 , width : maxWidth , height : 44 )
headerView . frame = headerFrame
}
}
}