0

How to design UI button like this in iOS? I not understand how to design this:

Image

rmaddy
  • 298,130
  • 40
  • 468
  • 517

2 Answers2

6

This is not very difficult and the the answer here should suffices the requirement with some modification nevertheless, I have created a button like you want. Please check the code from GitHub

Basically you can create an extension for the button and provide the desired properties there like rounded corner and specify the corner radius as per your requirement also which corner you want the radius to be applied i.e in your case top left and right bottom.

extension UIButton{
    func roundedButton(){
        let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
                                 byRoundingCorners: [.topLeft , .bottomRight],
                                 cornerRadii:CGSize(width:20.0, height:20.0))
        let maskLayer1 = CAShapeLayer()
        maskLayer1.frame = self.bounds
        maskLayer1.path = maskPAth1.cgPath
        self.layer.mask = maskLayer1

    }
}

This would give you a button like -

enter image description here

You can customise the text and colour of text as per your need.

That should be enough irrespective of number of custom buttons you want. Going with image and storyboard customisation would need rework for every button, hence I recommend this approach. Cleaner and better.

Community
  • 1
  • 1
Jeet
  • 4,527
  • 7
  • 34
  • 59
3

The easiest thing to do is to create a custom button with an image and just put those colored blobs in as the image for each button. Then add a title and adjust the color and font as needed. You can also create a mask layer as desired in the link provided by @Jetpack, although you may need to update the mask layer in a viewDidLayoutSubviews() method in your view controller.

Duncan C
  • 115,063
  • 19
  • 151
  • 241
  • 1
    Using images is not the easiest thing to do. It's actually the more difficult way. – rmaddy Feb 06 '17 at 04:24
  • @rmaddy, why do you say that? I've always found it easy. – Duncan C Feb 06 '17 at 04:36
  • 1
    See the other answer. Simple code. Easy to change as needed. With images you need to create each image with the proper color and all of the proper sizes. If you want to tweak it you need to edit all of the images. It's a pain. And it makes your app bigger having more images. – rmaddy Feb 06 '17 at 04:39
  • Ok, I see your point. In terms of the button code, the image approach is simpler, but you have a point about the pain of creating and maintaining images. I tend to prefer the code approach, but beginning developers might be intimidated by creating custom button classes. – Duncan C Feb 06 '17 at 11:44