Embossed text in UILabel - cocoa-touch

I need to draw an effect like this on a UILabel.
How can I do it?

U can try the below code. U can change the color of the text or the shadow based on the color of the background.
[label setShadowColor:[UIColor darkGrayColor]];
[label setShadowOffset:CGSizeMake(0, -1)];

If you're on gray background, I usually just use UILabel's text shadow property positioned one pixel below with color white. That comes quite close. If you really need more (i.e. if you want to have the dark edges above, then you need to write a custom label that draws the text multiple times). CoreGraphics can help you a bit with the CGContextSetShadow, though.

Related

How to create a small button with a large tappable area

I want to create a close button which will look like a circle with an x in the middle. In x code I set the button's size and width to be large so that the touchable area is larger (50 x 50 with a font of just 22).
I create a button, change the title to X and then set the following:
[self.closeButton.layer setBorderWidth:2.0f];
[self.closeButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
[self.closeButton.layer setCornerRadius:self.closeButton.bounds.size.width/2];
The circle border is too far from the X. How would I bring the borders in tighter to the X but not decrease the size of the clickable area?
assign image to a button. and make tappable area as you want. then set image location in button by setting inset value of that button as top, bottom, left, right. change the value of this according to your requirements. You can set inset value from interface builder as shown in image here. change the value and see the difference to place your image in button at exact location you want.
exactly like this image
I'd suggest exactly what Max has done. He has shown how to do this via IB, this is how you do it through code:
myButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 25, 25);// UIButton
myBarButtonItem.imageInsets = UIEdgeInsetsMake(0, 0, 25, 25);// UIBarButtonItem
EDIT:
Sorry for not reading your question properly the first time. I think you will run into the same issue with this approach : the border/cornerRadius of the button will not respect any insets. It will be drawn according to the frame of the button. Only (easy) workaround at the top of my head, is to create an image with the border and corners in it, and then set it as the image. The image will respect the insets, and you will have your desired tappable area, with the borders exactly where you want them.
There might be a more elegant workaround through subclassing, but unless you change the border width/color, or corner radius of your button at any stage, I'd suggest sticking with custom image.
EDIT 2:
Instead of using an image you might want to use this unicode character.

Why does UIButton render the titleLabel so terribly on iOS 7?

I'm using IcoMoon to create a custom font that I use to generate Icons. This however plays no role as the same phenomenon occurs using Helvetica.
Why do 2 things occur on titleLabel of a UIButton on iOS 7?
The right edge of the label is cut off (the button frame is much wider, but the label frame is getting cut off
there is a dark ring around the light gray image.
This looks absolutely horrible and it's basically unacceptable. We'll have to render graphics ourselves and localize images where appropriate.
I would be grateful for any info. The only thing that distinguishes these two checkmarks is that they have different colors set for titleColor
Try setBackgroundImage: instead of setImage:

Setting corner radius on UIDatePicker with a background color

I have a UIDatePicker in my view and have set the background color of the UIDatePicker:
self.datePicker.backgroundColor = [UIColor lightTextColor];
self.datePicker.layer.cornerRadius = 10;
This successfully puts a background behind the UIDatePicker (which in iOS7 is essentially transparent) but fails to make the rounded corners for the background that I am looking for (I do this same thing for an image on the screen and it works perfectly).
It seems that the corner radius doesn't affect the background color.
Is there a way to fix this problem by setting a corner radius for the background color (or any another solution).
The reason I want to do this is because the ordinary UIDatePicker looks awkward in the view I have constructed and looks much better with a background color.
However, all the other items in the view have rounded corners and I want the UIDatePicker to match them.
Thanks.
You have to add layer.masksToBounds=YES;
Try this,
self.datePicker.backgroundColor = [UIColor lightTextColor];
self.datePicker.layer.cornerRadius = 10;
self.datePicker.layer.masksToBounds=YES;
UIBuilder Swift 5 solution:
See picture, it's the same as #ToseefKhiji's solution but even easier to execute for fans of UIBuilder controls.
This is how it comes out (I have added other features to the picker programmatically, such as borderWidth, color, etc...)
UIBuilder is underappreciated by Swift/iOS coders as everyone has rushed to SwiftUI as the new new thing.

UITextView Text cut off when using setContentInset

I'm trying to shift the text in my UITextView right by 20 pixels to create a text indent using the code below
[textview setContentInset:UIEdgeInsetsMake(0, 20, 0,-20)];
But this is cutting off the right hand side of my text as shown in the screenshot. Can any help me stop this happening please
I think your edge insets are a bit off. Edge insets work towards the middle of the rectangle. For the right inset you should try 20 rather than -20.
[textview setContentInset:UIEdgeInsetsMake(0, 20, 0, 20)];
I couldn't find a solution to your problem even by subclassing UITextView and blocking setContentSize which seemed to be the problem.
[textview setContentInset:UIEdgeInsetsMake(0, 20, 0, rightInset)];
No matter what is the value of the rightInset the text is always clipped. Something is always redrawing text so that it fits the frame width of the text view.
But I am wondering why do you need to set the inset? Can't you just set the background of the UITextView object to clear color and position it properly on your background view to get the illusion of indentation?

How to hide NSTableView's white outline on a black window?

So what I've been trying to do was to put a NSTableView on a black background. However, for some kind of reason there's this white outline that wraps the NSTableView like this:
What I've got here is a translucent window with a subclassed NSTableView so that I can customize it's color. Alternating rows are turned on.
I've tried setting the grid color and background to a color with 0 alpha value, however nothing changes. Does anyone know why or how I can fix this? Thanks!
I think in Your NSTableView horizontal grid is turned on. You can turn off it in Attributes inspector and change colors also (grid and background).
Have you tried this:
tableView.backgroundColor = [UIColor clearColor];
tableView.separatorColor = [UIColor grayColor];
Your screenshot link is broken, so it’s hard to tell what you’re looking for exactly.
This answer might interest you, though: https://stackoverflow.com/a/4349459/135712
[yourTableView setIntercellSpacing:NSMakeSize(0.0, 0.0)];