Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add bevel effect to UIView

I want my button to look this.

enter image description here

I asked the designer and he said he has used bevel effect on it and I'm hearing the word bevel for the first time.

I searched Stack Overflow but couldn't find anything helpful.

like image 207
Drunken Daddy Avatar asked Nov 22 '18 08:11

Drunken Daddy


People also ask

Whats the difference between bevel and Emboss?

The bevel effects make an object look as though it has been chiselled away, and is great for giving hard, sharp edges. The emboss options are a bit softer and make objects seem to rise out of the document or look as though they have been stamped into the page.

What is bevel effect?

A bevel effect adds 3D depth to a graphic or text object by making its edges appear sloped (cut at an angle). Bevel effects can contain both spot and process (CMYK) colors, so they are ideal for printing.


1 Answers

I believe that the designer meant bevel and emboss effect. Here is a sample extension on UIImage for applying an emboss effect with a shader image.

extension UIImage {
    func applyBevelAndEmboss(shadingImage: UIImage) -> UIImage {
        // Create filters
        guard let heightMapFilter = CIFilter(name: "CIHeightFieldFromMask") else { return self }
        guard let shadedMaterialFilter = CIFilter(name: "CIShadedMaterial") else { return self }
        // Filters chain
        heightMapFilter.setValue(CIImage(image: self),
                                 forKey: kCIInputImageKey)
        guard let heightMapFilterOutput = heightMapFilter.outputImage else { return self }
        shadedMaterialFilter.setValue(heightMapFilterOutput,
                                      forKey: kCIInputImageKey)
        shadedMaterialFilter.setValue(CIImage(image: shadingImage),
                                      forKey: "inputShadingImage")
        // Catch output
        guard let filteredImage = shadedMaterialFilter.outputImage else { return self }
        return UIImage(ciImage: filteredImage)
    }
}

Do ask the designer for the shader image and to apply on the flat image.

My personal opinion is that, it is better to get the processed image from the designer and use it rather than performing all that processing in the app.

like image 128
Arun Balakrishnan Avatar answered Sep 22 '22 09:09

Arun Balakrishnan