UIStackView Bug

Sometimes you set items in UIStackView and it doesn’t work.
The bug is that hiding and showing views in a stack view is cumulative. Weird Apple bug. If you hide a view in a stack view twice, you need to show it twice to get it back.
http://www.openradar.me/25087688

To fix this issue you can use the following extension:

1
2
3
4
5
6
7
8
9
10
11
12
extension UIView {
var isHiddenInStackView: Bool {
get {
return isHidden
}
set {
if isHidden != newValue {
isHidden = newValue
}
}
}
}

and use:

1
stackView.subviews[someIndex].isHiddenInStackView = false

Dynamic change the App Icon

From iOS 10.3 Apple had added:

1
>var supportsAlternateIcons: Bool

A Boolean value indicating whether the app is allowed to change its icon.

1
>var alternateIconName: String?

The name of the icon being displayed for the app.

1
>func setAlternateIconName(String?, completionHandler: ((Error?) -> Void)?)

Changes the app’s icon.

3 things will allow us to change the App Icon dynamic.

We can change the icon only if the value of the supportsAlternateIcons property is true.
We must declare our app’s primary and alternate icons using the CFBundleIcons key of our app’s Info.plist file.
We can check keys here https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102043

Reference: https://medium.com/ios-os-x-development/dynamically-change-the-app-icon-7d4bece820d2

Fix break constraint UIActionSheet

Add an extension and call it before present.

1
2
3
4
5
6
7
8
9
10
11
actionSheetController.pruneNegativeWidthConstraints()

extension UIAlertController {
func pruneNegativeWidthConstraints() {
for subView in self.view.subviews {
for constraint in subView.constraints where constraint.debugDescription.contains("width == - 16") {
subView.removeConstraint(constraint)
}
}
}
}
© 2020 Vien's Blog All Rights Reserved.
Theme by hiero