iOS 13
This commit is contained in:
parent
04ab9ef056
commit
8fc03e75e0
@ -256,21 +256,19 @@ public typealias ActionBlock = () -> ()
|
||||
* appropriately called.
|
||||
* Only other reference found of issue: https://www.thetopsites.net/article/58142205.shtml
|
||||
*/
|
||||
if #available(iOS 13, *) {
|
||||
if let attributedText = attributedText, let text = text, !text.isEmpty {
|
||||
let attributedString = NSMutableAttributedString(string: text)
|
||||
let range = NSRange(location: 0, length: text.count)
|
||||
for attribute in attributedText.attributes(at: 0, effectiveRange: nil) {
|
||||
if attribute.key == .underlineStyle {
|
||||
attributedString.addAttribute(.underlineStyle, value: 0, range: range)
|
||||
}
|
||||
if attribute.key == .strikethroughStyle {
|
||||
attributedString.addAttribute(.strikethroughStyle, value: 0, range: range)
|
||||
}
|
||||
if let attributedText = attributedText, let text = text, !text.isEmpty {
|
||||
let attributedString = NSMutableAttributedString(string: text)
|
||||
let range = NSRange(location: 0, length: text.count)
|
||||
for attribute in attributedText.attributes(at: 0, effectiveRange: nil) {
|
||||
if attribute.key == .underlineStyle {
|
||||
attributedString.addAttribute(.underlineStyle, value: 0, range: range)
|
||||
}
|
||||
if attribute.key == .strikethroughStyle {
|
||||
attributedString.addAttribute(.strikethroughStyle, value: 0, range: range)
|
||||
}
|
||||
|
||||
self.attributedText = attributedString
|
||||
}
|
||||
|
||||
self.attributedText = attributedString
|
||||
}
|
||||
|
||||
hero = labelModel.hero
|
||||
|
||||
@ -49,125 +49,28 @@ import UIKit
|
||||
}
|
||||
heightConstraint?.constant = graphObject.diameter
|
||||
|
||||
// iOS 12 uses the conic gradient and a mask for simplicity.
|
||||
if #available(iOS 12, *) {
|
||||
let gradient = CAGradientLayer()
|
||||
gradient.type = .conic
|
||||
gradient.startPoint = CGPoint(x: 0.5, y: 0.5)
|
||||
gradient.endPoint = CGPoint(x: 0.5, y: 0.0)
|
||||
gradient.frame = CGRect(x: 0, y: 0, width: graphObject.diameter, height: graphObject.diameter)
|
||||
gradient.colors = graphObject.colors.map({ (color) -> CGColor in
|
||||
return color.cgColor
|
||||
})
|
||||
gradientLayer = gradient
|
||||
layer.addSublayer(gradient)
|
||||
|
||||
let center = CGPoint(x: gradient.bounds.midX, y: gradient.bounds.midY)
|
||||
let radius = (graphObject.diameter - graphObject.lineWidth) / 2.0
|
||||
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: (3 / 2 * .pi), endAngle: -(1 / 2 * .pi), clockwise: false)
|
||||
let mask = CAShapeLayer()
|
||||
mask.fillColor = UIColor.clear.cgColor
|
||||
mask.strokeColor = UIColor.white.cgColor
|
||||
mask.lineWidth = graphObject.lineWidth
|
||||
mask.path = path.cgPath
|
||||
gradient.mask = mask
|
||||
return
|
||||
}
|
||||
let gradient = CAGradientLayer()
|
||||
gradient.type = .conic
|
||||
gradient.startPoint = CGPoint(x: 0.5, y: 0.5)
|
||||
gradient.endPoint = CGPoint(x: 0.5, y: 0.0)
|
||||
gradient.frame = CGRect(x: 0, y: 0, width: graphObject.diameter, height: graphObject.diameter)
|
||||
gradient.colors = graphObject.colors.map({ (color) -> CGColor in
|
||||
return color.cgColor
|
||||
})
|
||||
gradientLayer = gradient
|
||||
layer.addSublayer(gradient)
|
||||
|
||||
//create circle path
|
||||
let radius = graphObject.diameter / 2.0
|
||||
|
||||
//begin point will be at the bottom, clockwise direction
|
||||
let path = UIBezierPath(arcCenter: CGPoint(x: radius
|
||||
, y: radius), radius: radius - graphObject.lineWidth/2.0, startAngle: CGFloat(Wheel.getPiValue(90.0)), endAngle: CGFloat(Wheel.getPiValue(90.0 + 360.0)), clockwise: true)
|
||||
path.lineWidth = graphObject.lineWidth
|
||||
|
||||
let circleLayer = CAShapeLayer()
|
||||
circleLayer.path = path.cgPath
|
||||
circleLayer.lineCap = .round
|
||||
circleLayer.lineWidth = graphObject.lineWidth
|
||||
circleLayer.fillColor = UIColor.clear.cgColor
|
||||
circleLayer.strokeColor = UIColor.black.cgColor
|
||||
|
||||
//create gradient layer
|
||||
let gradientLayer = createGradientLayer(graphObject)
|
||||
gradientLayer.mask = circleLayer
|
||||
layer.addSublayer(gradientLayer)
|
||||
self.gradientLayer = gradientLayer
|
||||
let center = CGPoint(x: gradient.bounds.midX, y: gradient.bounds.midY)
|
||||
let radius = (graphObject.diameter - graphObject.lineWidth) / 2.0
|
||||
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: (3 / 2 * .pi), endAngle: -(1 / 2 * .pi), clockwise: false)
|
||||
let mask = CAShapeLayer()
|
||||
mask.fillColor = UIColor.clear.cgColor
|
||||
mask.strokeColor = UIColor.white.cgColor
|
||||
mask.lineWidth = graphObject.lineWidth
|
||||
mask.path = path.cgPath
|
||||
gradient.mask = mask
|
||||
}
|
||||
|
||||
/*
|
||||
create three gradient layer for circle layout.
|
||||
_____________
|
||||
| → | top layer for smooth gradient
|
||||
-------------
|
||||
| | |
|
||||
| ↑ | ↓ |
|
||||
| | |
|
||||
-------------
|
||||
*/
|
||||
func createGradientLayer(_ graphObject: WheelModel) -> CALayer {
|
||||
let containLayer = CALayer()
|
||||
containLayer.frame = CGRect(x: 0, y: 0, width: graphObject.diameter, height: graphObject.diameter)
|
||||
let radius = graphObject.diameter / 2.0
|
||||
|
||||
//create graident layers
|
||||
guard graphObject.colors.count > 1 else {
|
||||
containLayer.backgroundColor = graphObject.colors.first?.cgColor
|
||||
return containLayer
|
||||
}
|
||||
var topGradientHeight : CGFloat = 0.0
|
||||
var leftColors = graphObject.colors.prefix(through: graphObject.colors.count/2)
|
||||
let rightColors = graphObject.colors.suffix(from: graphObject.colors.count/2)
|
||||
|
||||
// make the top layer higher than line width for smooth look
|
||||
topGradientHeight = min(max(graphObject.lineWidth, 1.0/(1.0+CGFloat(graphObject.colors.count))*graphObject.diameter), graphObject.diameter)
|
||||
let topLayer = CAGradientLayer()
|
||||
topLayer.frame = CGRect(x: 0.0, y: 0.0, width: graphObject.diameter, height: topGradientHeight)
|
||||
//make the graident edge more smoothy
|
||||
topLayer.startPoint = CGPoint(x: 0.25, y: 0.0)
|
||||
topLayer.endPoint = CGPoint(x: 0.75, y: 0.0)
|
||||
//if number of colors is even, need to display gradient layer, otherwise make top layer as solid color layer
|
||||
if graphObject.colors.count % 2 == 0 {
|
||||
leftColors.removeLast()
|
||||
let firstColor = leftColors.last!.cgColor
|
||||
let secondColor = rightColors.first!.cgColor
|
||||
topLayer.colors = [firstColor, secondColor]
|
||||
} else {
|
||||
topLayer.backgroundColor = leftColors.last?.cgColor
|
||||
}
|
||||
containLayer.addSublayer(topLayer)
|
||||
|
||||
let leftLayer = CAGradientLayer()
|
||||
leftLayer.frame = CGRect(x: 0, y: topGradientHeight, width: radius, height: graphObject.diameter - topGradientHeight)
|
||||
leftLayer.startPoint = CGPoint(x: 0, y: 1)
|
||||
leftLayer.endPoint = CGPoint(x: 0, y: 0)
|
||||
|
||||
//count of graidentLayer.colors must be bigger than 1, otherwise set backgroundColor
|
||||
if leftColors.count > 1 {
|
||||
leftLayer.colors = leftColors.map({ (color) -> CGColor in
|
||||
return color.cgColor
|
||||
})
|
||||
} else {
|
||||
leftLayer.backgroundColor = leftColors.first?.cgColor
|
||||
}
|
||||
containLayer.addSublayer(leftLayer)
|
||||
|
||||
let rightLayer = CAGradientLayer()
|
||||
rightLayer.frame = CGRect(x: radius, y: topGradientHeight, width: radius, height: graphObject.diameter - topGradientHeight)
|
||||
rightLayer.startPoint = CGPoint(x: 0, y: 0)
|
||||
rightLayer.endPoint = CGPoint(x: 0, y: 1)
|
||||
if rightColors.count > 1 {
|
||||
rightLayer.colors = rightColors.map({ (color) -> CGColor in
|
||||
return color.cgColor
|
||||
})
|
||||
} else {
|
||||
rightLayer.backgroundColor = rightColors.first?.cgColor
|
||||
}
|
||||
containLayer.addSublayer(rightLayer)
|
||||
|
||||
return containLayer
|
||||
}
|
||||
//MARK: MVMCoreUIViewConstrainingProtocol
|
||||
public func needsToBeConstrained() -> Bool {
|
||||
return true
|
||||
|
||||
@ -34,32 +34,18 @@
|
||||
self.model = model
|
||||
|
||||
// Set appearance
|
||||
if #available(iOS 13.0, *) {
|
||||
let appearance = UITabBarAppearance()
|
||||
appearance.backgroundColor = model.backgroundColor?.uiColor
|
||||
set(tabItemAppearance: appearance.stackedLayoutAppearance, model: model)
|
||||
set(tabItemAppearance: appearance.inlineLayoutAppearance, model: model)
|
||||
set(tabItemAppearance: appearance.compactInlineLayoutAppearance, model: model)
|
||||
standardAppearance = appearance
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
backgroundColor = model.backgroundColor?.uiColor
|
||||
tintColor = model.selectedColor.uiColor
|
||||
unselectedItemTintColor = model.unSelectedColor.uiColor
|
||||
barTintColor = model.backgroundColor?.uiColor
|
||||
isTranslucent = false
|
||||
}
|
||||
let appearance = UITabBarAppearance()
|
||||
appearance.backgroundColor = model.backgroundColor?.uiColor
|
||||
set(tabItemAppearance: appearance.stackedLayoutAppearance, model: model)
|
||||
set(tabItemAppearance: appearance.inlineLayoutAppearance, model: model)
|
||||
set(tabItemAppearance: appearance.compactInlineLayoutAppearance, model: model)
|
||||
standardAppearance = appearance
|
||||
|
||||
// Add buttons
|
||||
var tabs: [UITabBarItem] = []
|
||||
for (index, tab) in model.tabs.enumerated() {
|
||||
let tabBarItem = UITabBarItem(title: tab.title, image: MVMCoreCache.shared()?.getImageFromRegisteredBundles(tab.image), tag: index)
|
||||
tabBarItem.accessibilityLabel = tab.accessibilityText
|
||||
if #available(iOS 13.0, *) {
|
||||
} else {
|
||||
tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
|
||||
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: MFFonts.mfFontTXRegular(8)], for: .normal)
|
||||
}
|
||||
tabs.append(tabBarItem)
|
||||
}
|
||||
setItems(tabs, animated: false)
|
||||
@ -67,7 +53,6 @@
|
||||
}
|
||||
|
||||
/// Sets the item colors.
|
||||
@available(iOS 13.0, *)
|
||||
private func set(tabItemAppearance: UITabBarItemAppearance, model: TabBarModel) {
|
||||
tabItemAppearance.normal.iconColor = model.unSelectedColor.uiColor
|
||||
tabItemAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: model.unSelectedColor.uiColor, NSAttributedString.Key.font: MFFonts.mfFontTXRegular(8)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user