Creating utility for label with Icon

时间:2016-02-12 20:39:35

标签: ios swift icons label

I wanted a UILabel with icon.

So i created a utility which will create label, icon and deal with constraints for spacing between them etc.

Now when i use this component in my client code, i again need to create a UILabel in storyboard.

public static void main(String[] args) {
    String address, msg;
    int port, code;

    try {
        address = args[0];
        port = Integer.parseInt(args[1]);
        code = Integer.parseInt(args[2]);
        msg = args[3];
    } catch (Exception e) {
        // do something
    }
    // rest of main method
}

and

utility has prototype code:

 @IBOutlet weak var stateLabel: iconLabel! 
    ...
    stateLabel.style = withIcon

So problem is: 1)I have to have label in my client + in my utility. How to avoid this. 2)If i delete label from my client file, then that label has constraints with other labels in storyboard and i dont understand if i remove it, how can i use my utility. 3)If i dont recreate label in utility, then how can i set constraints between label and icon. 4) If i dont create utility, then every client has to have UIImageView for icon and code for constraints betweein icon and label. So i wanted to create a utility.

Any hints ?

Thanks.

1 个答案:

答案 0 :(得分:0)

Have a look at this basic tutorial by apple for creating custom views: Custom controls