trouble with rounded rectangles in Xcode 6 - swift

I'm a noob having trouble rounding the corners of my buttons using interface builder in Xcode 6.
I added a new User Defined Runtime Attribute (layer.cornerRadius) as per the below instructions:
https://stackoverflow.com/a/25164977/2903220
Unfortunately when I run the app there is no change in the button.
All other answers I've found say to do the same thing, yet it's not working.
My questions is are there other settings I should check which may cause this to not work?
(maybe it's better to do it programatically?!)
Please help! Thanks!

button.clipsToBounds = YES;
button.layer.cornerRadius = 20;//half of the width
button.layer.borderColor=[UIColor redColor].CGColor;
button.layer.borderWidth=2.0f;

Checking Clip Subviews in the attributes inspector solves the issue.

Related

Rounded corners on an NSTextView/NSScrollView?

There is a similar question already on here but it is in objective C. The answer in objective C is apparently:
[self.textView.layer setCornerRadius:10.0f];
I've tried translating this into Swift a few different ways. I'm guessing I want something like this (or maybe there is now a completely different way of doing it given that the obj-c question was posted way back in 2012):
consoleTextView.layer.setCornerRadius(10)
I can't see an option for it in the attributes inspector on xcode either. Maybe it's the NSScrollView that needs changing, I don't know. Hopefully someone with more experience in swift/xcode can help me out.
EDIT- As requested, how the consoleTextView is created:
consoleTextView = consoleScrollView.documentView as? NSTextView
EDIT- Picture of scroll/textView, it's the grey box at the bottom. It's used as a terminal-like window.
I managed to solve my problem:
consoleScrollView.wantsLayer = true
consoleScrollView.layer?.cornerRadius = 10
That works ^
You could also do the same with the TextView but you will be left with the square outline of the ScrollView behind it, so if you're trying to achieve the same thing as me you'll have to do it with the ScrollView as well anyway.

How to make the UIKeyboard black?

I've seen this SO question here: Can I tint (black) a UIKeyboard? If so, how?, where the top answer suggests that you can hack around but doing so may get your app rejected by Apple. This must not be true, as I've seen other iPhone applications (a major one being Clear) that have a black UIKeyboard. How is it done?
Here's a screenshot of Clear for reference:
Try this out
[(UITextField *)mySubView setKeyboardAppearance:UIKeyboardAppearanceAlert];
or just adding setKeyboardAppearance:UIKeyboardAppearanceAlert appropriately depending on how you have this set up!
Isnt this the [textView setKeyboardAppearance:UIKeyboardAppearanceAlert]; style?
Otherwise, as stated. It's not possible without hacking the subviews. Of course you can still setup your own complete inputView.
Starting in iOS 7, you can use UIKeyboardAppearanceDark
So, for example:
self.textField.keyboardAppearance = UIKeyboardAppearanceDark

UITextField background behaviour change from iOS 4 to iOS 5

In my app I have a UITextField which is on top of a background image. Under iOS 4 I had to set the backgroundColor property to 'clearColor' in order to make it look right. Under iOS 4 the textfield looks like this...
This is how I want it to look. Now, since upgrading to Xcode 4.3 (iOS 5) when I re-run the same project, the box looks like this...
Grrr. So under iOS 5 I changed the backgroundColor property to 'whiteColor' and it works fine. However now, under iOS 4.x the box looks like this...
Note the ugly white corners! So please, can anyone tell me what I should be doing here in order to get it to look normal under both iOS 4 and iOS 5 (i.e. To look like the first image!).
Many thanks,
Simon
I got the same problem a few days ago. To solve this, I just set the borderStyle and comment the backgroundColor line. Everything just work fine, both iOS4 and iOS5.
// textField.backgroundColor = [UIColor clearColor]; // just leave it, dont't set
textField.borderStyle = UITextBorderStyleRoundedRect;
This is what i did to resolve this issue, you can check the version of iOS running on the device and do the handling accordingly, like this
float version = [[[UIDevice currentDevice]systemVersion]floatValue];
if(version < 5.0)
{
//user clear color
}else
{
//use white color
}
Hope this helps you.
Sometimes you might have to rebuild your project. Also, try and make this in a whole new project to see if it is actually a new change to Xcode, or if it is just that particular project to narrow things down. If you then isolate it to being something wrong with your particular project, try and "do it over" to see if it clicks then. But i see you solved it :=)

UILabel text on iPad not resizing

I have iOS 4.3 installed on my iPad. I'm noticing that my text in my UILabels is not resizing. In other words, I'm adding letters, but it's just truncating. Same settings work find on iPhone also running 4.3. I'm perplexed. I've made certain that "Adjust to fit" is checked on the label properties. I've even set it in the code with .adjustsFontSizeToFitWidth and even tried calling sizeToFit.
None of these let the text resize.
Does anyone else have this problem?
Any ideas?
My next solution is going to use this: Check if label is truncated to try and manually resize the label text.
I finally figured it out. I'm using OHAttributedLabel. I had intended to do some things with color in my labels and have not yet gotten around to it. It finally dawned on me that was the only difference from previous iPad versions and from the iPhone version (I never even thought to look at the class). Turns out this OHAttributedLabel class does not support resizing yet.
Sorry for wasting everyones time. Maybe someone else will someday find this useful.
Try using CGSize eLabelSize = [yourLabel.text sizeWithFont:yourLabel.font]; to get the size of the label and then you can simply modify the yourLabel.frame.size property with eLabelSize.
This worked for me in case of iPhone.
Hope this works for you if yes do communicate..... :)
Maybe it only appears as if the label is truncating text because the label frame runs out of the bounds of its parent view, which clips to its bounds? Verify the frame of the label and the autoresizing mask.
Also, the minimumFontSize property is set low enough?

UIActivityIndicatorView doesn't work on iPhone 4 with iOS4

I noticed in one of my apps that the activity indicator doesn't seem to work on an iPhone 4. It works fine on an old iPhone upgraded to iOS 4 just not on an iPhone 4. Does anyone know why it isn't working?
This code should do the job, is that correct;)?
#import <QuartzCore/QuartzCore.h>
...
activityIndicatorInstance.layer.shadowColor = [UIColor grayColor].CGColor;
activityIndicatorInstance.layer.shadowRadius = 1;
activityIndicatorInstance.layer.shadowOpacity = 0.5;
activityIndicatorInstance.layer.shadowOffset = CGSizeMake(0, 1);
oddly it uses a transparent alpha channel on the iPhone 4.
A solution may be to add a kind of background...
I had the same problem, but found that if I coded it rather than using Interface Builder it worked.
If your design allows, you can also use the UIActivityIndicatorViewStyleGray or attempt to add a dark shadow to the activityView's layer.
I solve the problem, in iOS5 the frame size is already set. In iOS4 you need to set the frame size yourself. Hope it helps.