Rounded corners on an NSTextView/NSScrollView? - swift

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.

Related

Some Border Types in NSImageView Not Appearing

I've looked in previous posts in SO and elsewhere for an answer but no luck. I'm putting images in an NSCollectionView as well as just a single image itself but the only border that seems to work is the grey Bezel border. Other types that are available don't show up, like Button or Groove. This is true no matter what scaling option I use, or even if I use it in code. I'm using NSImageView.imageFrameStyle.
I hope someone has some insight into this. I didn't provide any code since I didn't think that's necessary. Using Xcode 10.1, Swift 4.2. Thanks for any help.

controls in notification center today widget have their colours inverted

I'm building an app extension for the Today section of the Notification Centre in OSX. My problem is that when I add controls like NSTableView or NSDatePicker their colours get inverted. NSTextField and NSButton seem to get inverted to, but they look great when they do. However, NSTableView does not look good, and I'd like it to display like it does in a normal window.
I don't have enough reputation to post an image apparently, so you'll have to checkout this screenshot to see what I mean.
I've tired fixing this programmatically in swift by setting the NSTableView's appearence property but that doesn't seem to fix my problem.
tableView.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
Does anybody know how to fix this?

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?

scrollRectToVisible with multiple UIScrollView not working?

I've a big issue with "scrollRectToVisible" method, part of UIScrollView class.
I've a view with 4 UIScrollView displayed from top to bottom, with paging in the width way :
I can browse in them (like the in the "pictures" app, but with 4 images on the same view)
i can resize the height of each of them
everything works fine
Now, I want to use "scrollRectToVisible" in order to "randomize" the pages displayed in each UIScrollView.
The problem is that :
this function work for only 1 or 2 UIScrollViews (even if I call this for the 4)
if I resize the UIScrollViews with a "random" size for each of them, most of the time, only the "highest" can make this function running
I can't really figure out a rationnal explanation why some of them are working, and the other not
btw, it seems that there is a link between the height of the UIScrollView and the fact that the method works or not.
I'm quite disapointed because... I just feel like it's a bug in the system... but maybe I missed something mandatory to make this method work on my 4 UIScrollView...
PS : i'm not mad, but i'm becoming crazy... lol
PS2 : i've also verified all the contentView, contentSize, frames of my UIScrollViews and content... I don't see any reason why it does not work correctly.... because the "normal" touch-scroll works pretty fine !
Thanks for any tips or help
Try this UIScrollView sample: Scrolling
This question is too vague and undocumented to really know what your problem is. What heights are we talking here? If you're going lower than like 20 pixels, you might be running into touch problems where the touch isn't getting sent to the right place. Please post some suspect code, or even setup code and try to ask more directed questions. I'm happy to update my answer as needed.

How do i change color of letters of sectionIndexTitlesForTableView?

Hope you all are fine and also in best of your moods.
I have a little problem kindly help me to get its solution.
my Problem is:
I am using vertical search in my application, using method sectionIndexTitlesForTableView() of tableview i get all Character listed from top to bottom at rightside.
But this letters have fixed color. i need to change this color. Since i newbie i don't know how to deal with it.
Please help to get solution.
Thanks, and sorry if you found me with wrong english.
There is no supported way to do this. Even if you had access to the index view (which you don't easily), it would not be possible because there is no NSAttributedString on iPhone, so you couldn't return color information.
The best way to achieve this is to turn off the tableview's index and generate your own from scratch, floating it over top of the tableview. But I would not recommend this approach for a new iPhone developer. It is best to spend some serious time learning to build UIs the way Apple intends you to. Once you understand Apple's UI and how it's implemented, then you can make informed decisions about whether you should break the UI rules.