session-ios/SignalServiceKit/src/Util/UIView+OWS.h

175 lines
5.8 KiB
C
Raw Normal View History

2017-01-12 21:55:14 +01:00
//
2018-01-05 20:42:50 +01:00
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
2017-01-12 21:55:14 +01:00
//
2017-02-13 22:30:54 +01:00
#import <PureLayout/PureLayout.h>
2017-01-12 21:55:14 +01:00
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
2017-01-12 21:55:14 +01:00
// A convenience method for doing responsive layout. Scales between two
// reference values (for iPhone 5 and iPhone 7 Plus) to the current device
// based on screen width, linearly interpolating.
CGFloat ScaleFromIPhone5To7Plus(CGFloat iPhone5Value, CGFloat iPhone7PlusValue);
// A convenience method for doing responsive layout. Scales a reference
// value (for iPhone 5) to the current device based on screen width,
// linearly interpolating through the origin.
CGFloat ScaleFromIPhone5(CGFloat iPhone5Value);
// A set of helper methods for doing layout with PureLayout.
@interface UIView (OWS)
// Pins the width of this view to the width of its superview, with uniform margins.
2017-10-10 22:13:54 +02:00
- (NSArray<NSLayoutConstraint *> *)autoPinWidthToSuperviewWithMargin:(CGFloat)margin;
- (NSArray<NSLayoutConstraint *> *)autoPinWidthToSuperview;
2017-01-12 21:55:14 +01:00
// Pins the height of this view to the height of its superview, with uniform margins.
2017-10-10 22:13:54 +02:00
- (NSArray<NSLayoutConstraint *> *)autoPinHeightToSuperviewWithMargin:(CGFloat)margin;
- (NSArray<NSLayoutConstraint *> *)autoPinHeightToSuperview;
2017-01-12 21:55:14 +01:00
- (NSArray<NSLayoutConstraint *> *)ows_autoPinToSuperviewEdges;
- (NSArray<NSLayoutConstraint *> *)ows_autoPinToSuperviewMargins;
2017-10-02 20:26:03 +02:00
- (NSLayoutConstraint *)autoHCenterInSuperview;
- (NSLayoutConstraint *)autoVCenterInSuperview;
2017-01-12 21:55:14 +01:00
- (void)autoPinWidthToWidthOfView:(UIView *)view;
- (void)autoPinHeightToHeightOfView:(UIView *)view;
- (NSLayoutConstraint *)autoPinToSquareAspectRatio;
- (NSLayoutConstraint *)autoPinToAspectRatio:(CGFloat)ratio;
2017-01-12 21:55:14 +01:00
#pragma mark - Content Hugging and Compression Resistance
- (void)setContentHuggingLow;
- (void)setContentHuggingHigh;
- (void)setContentHuggingHorizontalLow;
- (void)setContentHuggingHorizontalHigh;
- (void)setContentHuggingVerticalLow;
- (void)setContentHuggingVerticalHigh;
- (void)setCompressionResistanceLow;
- (void)setCompressionResistanceHigh;
- (void)setCompressionResistanceHorizontalLow;
- (void)setCompressionResistanceHorizontalHigh;
- (void)setCompressionResistanceVerticalLow;
- (void)setCompressionResistanceVerticalHigh;
2017-05-16 18:25:12 +02:00
#pragma mark - Manual Layout
- (CGFloat)left;
- (CGFloat)right;
- (CGFloat)top;
- (CGFloat)bottom;
- (CGFloat)width;
- (CGFloat)height;
- (void)centerOnSuperview;
#pragma mark - RTL
// For correct right-to-left layout behavior, use "leading" and "trailing",
// not "left" and "right".
//
2017-07-21 16:36:45 +02:00
// These methods use layoutMarginsGuide anchors, which behave differently than
// the PureLayout alternatives you indicated. Honoring layoutMargins is
// particularly important in cell layouts, where it lets us align with the
// complicated built-in behavior of table and collection view cells' default
// contents.
//
// NOTE: the margin values are inverted in RTL layouts.
2018-06-22 19:48:23 +02:00
- (NSArray<NSLayoutConstraint *> *)autoPinLeadingAndTrailingToSuperviewMargin;
- (NSLayoutConstraint *)autoPinLeadingToSuperviewMargin;
- (NSLayoutConstraint *)autoPinLeadingToSuperviewMarginWithInset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinTrailingToSuperviewMargin;
- (NSLayoutConstraint *)autoPinTrailingToSuperviewMarginWithInset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinTopToSuperviewMargin;
- (NSLayoutConstraint *)autoPinTopToSuperviewMarginWithInset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinBottomToSuperviewMargin;
- (NSLayoutConstraint *)autoPinBottomToSuperviewMarginWithInset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinLeadingToTrailingEdgeOfView:(UIView *)view;
- (NSLayoutConstraint *)autoPinLeadingToTrailingEdgeOfView:(UIView *)view offset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinTrailingToLeadingEdgeOfView:(UIView *)view;
- (NSLayoutConstraint *)autoPinTrailingToLeadingEdgeOfView:(UIView *)view offset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinLeadingToEdgeOfView:(UIView *)view;
- (NSLayoutConstraint *)autoPinLeadingToEdgeOfView:(UIView *)view offset:(CGFloat)margin;
- (NSLayoutConstraint *)autoPinTrailingToEdgeOfView:(UIView *)view;
- (NSLayoutConstraint *)autoPinTrailingToEdgeOfView:(UIView *)view offset:(CGFloat)margin;
2017-07-12 17:39:54 +02:00
// Return Right on LTR and Left on RTL.
- (NSTextAlignment)textAlignmentUnnatural;
// Leading and trailing anchors honor layout margins.
// When using a UIView as a "div" to structure layout, we don't want it to have margins.
- (void)setHLayoutMargins:(CGFloat)value;
2018-06-28 16:42:37 +02:00
- (NSArray<NSLayoutConstraint *> *)autoPinToEdgesOfView:(UIView *)view;
2018-01-05 20:42:50 +01:00
#pragma mark - Containers
+ (UIView *)containerView;
+ (UIView *)verticalStackWithSubviews:(NSArray<UIView *> *)subviews spacing:(int)spacing;
2017-01-12 21:55:14 +01:00
#pragma mark - Debugging
- (void)addBorderWithColor:(UIColor *)color;
- (void)addRedBorder;
// Add red border to self, and all subviews recursively.
- (void)addRedBorderRecursively;
2018-01-18 17:39:12 +01:00
#ifdef DEBUG
- (void)logFrame;
- (void)logFrameWithLabel:(NSString *)label;
- (void)logFrameLater;
- (void)logFrameLaterWithLabel:(NSString *)label;
- (void)logHierarchyUpwardLaterWithLabel:(NSString *)label;
2018-01-18 17:39:12 +01:00
#endif
2017-01-12 21:55:14 +01:00
@end
2018-04-09 20:56:33 +02:00
#pragma mark -
@interface UIScrollView (OWS)
2018-07-17 15:25:42 +02:00
// Returns YES if contentInsetAdjustmentBehavior is disabled.
- (BOOL)applyScrollViewInsetsFix;
2018-04-09 20:56:33 +02:00
@end
#pragma mark -
@interface UIStackView (OWS)
- (void)addBackgroundViewWithBackgroundColor:(UIColor *)backgroundColor;
@end
#pragma mark - Macros
CG_INLINE CGSize CGSizeCeil(CGSize size)
{
return CGSizeMake((CGFloat)ceil(size.width), (CGFloat)ceil(size.height));
}
2018-06-22 19:48:23 +02:00
CG_INLINE CGSize CGSizeFloor(CGSize size)
{
return CGSizeMake((CGFloat)floor(size.width), (CGFloat)floor(size.height));
}
CG_INLINE CGSize CGSizeRound(CGSize size)
{
return CGSizeMake((CGFloat)round(size.width), (CGFloat)round(size.height));
}
2018-06-28 17:02:18 +02:00
CG_INLINE CGSize CGSizeMax(CGSize size1, CGSize size2)
{
return CGSizeMake(MAX(size1.width, size2.width), MAX(size1.height, size2.height));
}
2018-07-05 17:56:46 +02:00
CGFloat CGHairlineWidth(void);
2018-06-29 18:49:23 +02:00
NS_ASSUME_NONNULL_END