Giter Site home page Giter Site logo

vienvu89.github.io's People

Contributors

vienvu89 avatar

Watchers

James Cloos avatar  avatar

vienvu89.github.io's Issues

Only allow int or double NSTextField

     func controlTextDidChange(_ obj: Notification) {
        if let textfield = obj.object as? NSTextField,
            textfield == widthTextField || textfield == heightTextField {

            var stringValue = textfield.stringValue

            // First step : Only '1234567890.' - @Clifton Labrum solution
            let charSet = NSCharacterSet(charactersIn: "1234567890.").inverted
            let chars = stringValue.components(separatedBy: charSet)
            stringValue = chars.joined()

            // Second step : only one '.'
            let comma = NSCharacterSet(charactersIn: ".")
            let chuncks = stringValue.components(separatedBy: comma as CharacterSet)
            switch chuncks.count {
            case 0:
                stringValue = ""
            case 1:
                stringValue = "\(chuncks[0])"
            default:
                stringValue = "\(chuncks[0]).\(chuncks[1])"
            }

            // replace string
            textfield.stringValue = stringValue
        }
    }

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:

extension UIView {
    var isHiddenInStackView: Bool {
        get {
            return isHidden
        }
        set {
            if isHidden != newValue {
                isHidden = newValue
            }
        }
    }
}

and use:

stackView.subviews[someIndex].isHiddenInStackView = false

Universal link iOS

xcrun supports opening URLs on iOS simulator as if they have been triggered by a user action.
So we can trigger it to test

xcrun simctl openurl booted https://www.example.com/chapter/123

or Schemes

xcrun simctl openurl booted โ€œapp://example/chapter?id=2โ€

Fix break constraint UIActionSheet

Add an extension and call it before present.

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)
            }
        }
    }
}

Reload Cell without anymation

Sometimes, the collectionView or tabelView has the dynamic cell's height can flickers while reloading cells individually.
We can use this code to avoid it:

UIView.performWithoutAnimation {
      self.tableView.reloadRows(at: [indexPath], with: .none)
}

Dynamic change the App Icon

From iOS 10.3 Apple had added:

var supportsAlternateIcons: Bool

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

var alternateIconName: String?

The name of the icon being displayed for the app.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.