0

I would like my UITextView to have the special shadowed border as in the attached picture.

enter image description here

How can I achieve it in xcode 4.4 without locating a background image?

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
Dejell
  • 13,947
  • 40
  • 146
  • 229

2 Answers2

0

I'm not sure if this is able only through custom drawing (i.e. Quartz/Core Graphics). I'd still use a pre-rendered image if somehow possible. Check out this post for that.

But this one comes maybe close to the desired effect:

    [yourTextView.layer setBackgroundColor: [[UIColor whiteColor] CGColor]];
    [yourTextView.layer setBorderColor: [[UIColor grayColor] CGColor]];
    [yourTextView.layer setBorderWidth: 1.0];
    [yourTextView.layer setCornerRadius: 8.0f];
    [yourTextView.layer setMasksToBounds: YES];

don't forget to import:

#import <QuartzCore/QuartzCore.h>
Community
  • 1
  • 1
Nenad M
  • 3,055
  • 20
  • 26
0

Here is what I have done to achieve the look:

  • create a container view, say m wide by n high. Set it to clip subviews, and give its CALayer a corner radius

  • create the text box using a rectangular view, set a corner radius, and have its origin.y be some small number - say 8. Adjust the height so its 2x the offset

  • create a UIView subclass that uses a CAGradient layer, and have the gradient use a linear gradient starting at the top and becoming lighter as y increases.

  • as above, create another gradient view where the gradient starts at the bottom and moves up (the white one) or maybe just use a solid white view

  • add the first gradient view to the container view, then the second, then the text box.

The second gradient view needs to fade to a clear color so that it does not block the view underneath it (you can play around with the order of the two 'effects' views.

David H
  • 40,852
  • 12
  • 92
  • 138
  • Do you have a code sample for it? and I don't know what will be the size of the UITextView - since it should be the same code for all – Dejell Dec 04 '12 at 17:25
  • Sorry no code. You will find lots of examples on SO of how to use a CAGradientLayer. Once you get it working more or less the text view can be anything - a UIView subclass, a label, a textview etc. You have lots of points - put a bounty of say 100 points for working code and I will be amazed if someone (looking for points!) doesn't respond soon. Ask for a sample project posted on Dropbox or equiv (what I have done to get bounties myself). – David H Dec 04 '12 at 18:17