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)];
Related
I'm presenting a view in an NSPopover, using code based on this sample code.
The view, and all of its sub-views, are layer-backed. There's a single NSImageView, and several non-editable NSTextFields. The text fields backgroundColors are set to [NSColor textBackgroundColor], and their textColors to [NSColor textColor]. In this way, the text is black if one is using the normal theme, and white if one is using the "dark menu bar and Dock" option (which I'll refer to as "dark theme" from now on). This all works fine, and it looks a little somethin' like this:
Light theme:
Dark theme:
The problem comes when I animate the NSImageView up off the view. As it intersects with the NSTextFields, the image appears to blend with the text fields in an unappealing manner. It happens in both light and dark themes, but it's more icky-looking (it's a technical term) in the dark theme. Dig it:
The code to animate it looks basically like this:
CABasicAnimation* positionAnimation = [CABasicAnimation animationWithKeyPath:#"position"];
positionAnimation.fromValue = [NSValue valueWithPoint:fromPoint];
positionAnimation.toValue = [NSValue valueWithPoint:toPoint];
positionAnimation.duration = imageAnimationDuration;
[self.imageView.layer addAnimation:positionAnimation forKey:#"position"];
self.imageView.layer.position = toPoint;
What have I tried? Oh, what haven't I tried?
First off, my own views don't have any kind of NSVisualEffectView going on. But it seems that NSPopover adds that on its own; you can clearly see my desktop bleeding through the popover in the animation above. That's fine; it's actually a nice effect. But, thinking that my NSImageView was trying to be vibrant, I subclassed NSImageView just to return NO from allowsVibrancy. No change in behavior.
Next, I subclassed NSView to return NO from allowsVibrancy, and made the parent view of my view an instance of that. No change in behavior.
My NSTextFields are set with drawsBackground = NO, so I changed them to YES. No change in behavior. Then, leaving drawsBackground = YES, I set both text field's backgroundColors to [NSColor clearColor]. Here's where it gets weird. This does make the weird drawing go away, but it changes the text color of one of the text fields (the smaller one) to black. Wut? See below.
I gave up on the background colors, and started messing with the text colors. I found that if I set the textColor of the text fields to a discrete color (say, [NSColor blackColor] or [NSColor whiteColor], then the weird drawing problem also goes away. It seems only to get weird when using colors which adapt with the theme such as [NSColor textColor]. That's super lame, because the whole point of using something like [NSColor textColor] is that it adapts to the theme. I could probably hack around and figure out what theme is active and set the colors manually, but I really don't want to go that route if I can help it.
I promise there's a question in here somewhere, and, mercifully, here it is:
How can I fix the animation issue shown above, while still using colors which properly adapt to the current theme?
Sample project on GitHub.
Edit:
The desired result is to have no blending between the image and the text. Something like this:
The image I used in the sample app here maybe isn't the best example to convey the sheer yuckiness of the animation I'm seeing in my actual app. The image in the sample is already mostly white, while in my actual app it's mostly black, and it truly looks horrible when blended with white text.
Visual Effect Views (like used in NSPopover) are totally messed up in OS X Yosemite and they are causing your problem here. It is not your fault, these views are totally buggy.
A workaround on Yosemite should be to set the appearance property of each NSTextField to NSAppearanceNameAqua. Because if the labels don't try to do some weird vibrancy effect, they can't mess things up. The labels still look the same and the strange effect is gone.
My words in code:
self.titleLabel.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
self.descriptionLabel.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
Luckily NSVisualEffectView's are working fine now in El Capitan. So your code should work fine there..
I need a UITableView with no background color at all since I have the same Background image for
every page within my app.
I know this was asked several times before, but none of the solutions posted here work for me.
I tried the
.backgroundView = nil
.backgroundColor = [UIColor clearColor]
thing for cells and tableview but the result was that I got a white background.
Some posts said that this is the new iOS7 standard.
I tried to set a color with an alpha value like this
.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
but that just gives me a black cell instead of a transparent one. So Aparently everything except the alpha value is applied here.
Also I got the problem that if you scroll the table over the "borders" there is still a white background. Is this the normal background of the tableview itself and would not be seen once the tableview did finally has an alpha value?
Oh, ofc appling an opacity-value from 0 in the inspector won't work either.
Am I missing something, is there a new way of doing this, is it even possible to have UITableViews that are complete transparent (excluding labels and images I've put in there of course)?
If that matters, I am currently using xCode 5.1.1
Thanks for any help.
Try:
cell.contentView.backgroundColor = [UIColor clearColor];
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.
In iOS 7, if I set the toolbar background color, it uses a washed out version of the color, not the actual color. At first I thought maybe the toolbar was semi-transparent (not fully opaque) but that doesn't appear to be the problem.
Even using black only give me a light grey color.
[topToolbar setBackgroundColor:[UIColor blackColor]];
I also tried:
[topToolbar setTranslucent:NO];
But that just caused my toolbar color to be ignored completely.
Anybody know how to make it just use the color specified, without any weirdness?
Thanks.
I wasn't aware of the setBarTintColor method previously, but it is what is needed to accomplish this.
[topToolbar setBarTintColor:[UIColor blackColor]];
[topToolbar setTranslucent:NO];
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.