remove shadow from HorizontalBarChartView - ios-charts

My HorizontalBarChartView has a drop shadow. How can I remove it?
The chart is setup like this:
chartView.userInteractionEnabled = NO;
chartView.drawGridBackgroundEnabled = NO;
chartView.drawBarShadowEnabled = NO;
chartView.drawBordersEnabled = NO;
chartView.leftAxis.enabled = NO;
chartView.rightAxis.enabled = NO;
chartView.drawValueAboveBarEnabled = NO;

Try disable BarChartView.drawBarShadowEnabled
There is shadowColor in BarChartDataSet too:
/// the color used for drawing the bar-shadows. The bar shadows is a surface behind the bar that indicates the maximum value
public var barShadowColor = UIColor(red: 215.0/255.0, green: 215.0/255.0, blue: 215.0/255.0, alpha: 1.0)

If your are using swift instead of objc, just replace 'NO' by 'false'
chartView.drawBarShadowEnabled = false
edit :
From the code source :
/// if set to true, a grey area is drawn behind each bar that indicates the maximum value
173 #objc open var drawBarShadowEnabled: Bool
in ChartsDemo example link
//: ### General
chartView.pinchZoomEnabled = false
chartView.drawBarShadowEnabled = false
chartView.doubleTapToZoomEnabled = false
chartView.drawGridBackgroundEnabled = true
chartView.fitBars = true

Related

Can't set disabled UITextField background color to clear

In TvOS, I can't seem to get a UITextField to render with a clear background. Please note I am also using Xamarin as an intermediary.
var label = new UITextField()
{
Text = seperator,
UserInteractionEnabled = false,
BackgroundColor = UIColor.Clear,
VerticalAlignment = UIControlContentVerticalAlignment.Top
};
parent.AddArrangedSubview(label);
label.TranslatesAutoresizingMaskIntoConstraints = false;
label.HeightAnchor.ConstraintEqualTo(200).Active = true;
label.TextAlignment = UITextAlignment.Center;
The parent in this case is a UIStackView.
Here is the output:
It seems to work perfectly fine if you set it to any other color.
Any solutions would be greatly appreciated.

Can't set the same color for background and border in UISegmentedControl

I am trying to customize my segmented control with Swift, but I have run into a problem. I set the same color (e.g. UIColor.red) for border and background, but they look different. My code is:
segmentedControl.layer.cornerRadius = 12
segmentedControl.layer.borderWidth = 2
segmentedControl.layer.borderColor = UIColor.red.cgColor
segmentedControl.layer.masksToBounds = true
segmentedControl.backgroundColor = .red
Maybe someone knows how can I fix it?
Try setting the tintColor and selectedSegmentTintColor:
segmentedControl.tintColor = .white
segmentedControl.selectedSegmentTintColor = .white

iOS 13 system color for UIButton

Apple recommends using system colors to adapt apps to light and dark mode automatically, for example:
myLabel.textColor = UIColor.secondaryLabel
Here Apple lists various properties to be used, such as the one in the example above, and system colors for background, placeholder text, and more.
But it doesn't list a property for UIButton elements.
Which property or other method should we use to adapt UIButtons to theme changes?
As of now, I'm doing this:
myButton.tintColor = UIColor.link
which is supposedly for links but is the only "clickable" property I found.
I'm not looking to use something like UIColor.systemRed, rather something like UIColor.systemBackground, which adapts automatically to the current theme.
I hope you create colored Assets not one by one. You can use this function to tint images as a extension of UIImageView. I also use the same technique for buttons.
func setImageAndColor(image: UIImage, color: UIColor) {
let templateImage = image.withRenderingMode(.alwaysTemplate)
self.image = templateImage
self.tintColor = color
}
In case you want to define all you own colors, I suggest to create a singleton class named Colors:
import UIKit
class Colors {
static let shared = Colors()
var statusBarStyle: UIStatusBarStyle = .lightContent
private init(){}
func setLightColors() {
statusBarStyle = .darkContent
yourColor = UIColor( // choose your favorite color
styleColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)//white
labelColor = UIColor(red: 15/255, green: 15/255, blue: 15/255, alpha: 1)
subLabelColor = UIColor(red: 25/255, green: 25/255, blue: 25/255, alpha: 1)
............ set values for all colors from here.
}
func setDarkColors() {
statusBarStyle = .lightContent
yourColor = // choose your favorite color
............
}
// set initial colors
var yourColor: UIColor =
}
If somebody is interested in the whole Colors class, text me or comment below.
I access the colors singleton by:
Colors.shared.yourColor
Also for first configuration I set in the very first VC the darkmode number (0-Auto; 1-On; 2-Off):
if darkmodeNumber == 0 {
if traitCollection.userInterfaceStyle == .light {
print("Light mode")
Colors.shared.setLightColors()
} else {
print("Dark mode")
Colors.shared.setDarkColors()
}
} else if darkmodeNumber == 1 {
Colors.shared.setDarkColors()
} else if modeNumber == 2 {
Colors.shared.setLightColors()
}
}
The statusbar should then change also the right way.
Use any system colors you like. They are all adaptive. I applied the system gray color to a button's text:
The color changes when we switch between light and dark mode.

Masking A UIView With UILabel Using AutoLayout

I am working on a project that would result in this desired effect:
I am successfully drawing my circle using the following code:
let circle = CircleView()
circle.translatesAutoresizingMaskIntoConstraints = false
circle.backgroundColor = UIColor.clear
self.addSubview(circle)
// Setup constraints
circle.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
circle.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
circle.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.6).isActive = true
circle.heightAnchor.constraint(equalTo: circle.widthAnchor, multiplier: 1.0/1.0).isActive = true
For reference, this is my CircleView class:
class CircleView: UIView {
override func draw(_ rect: CGRect) {
// Set the path
let path = UIBezierPath(ovalIn: rect)
// Set the fill color
UIColor.black.setFill()
// Fill
path.fill()
}
}
Subsequently, I am then creating my UILabel, as such:
let myLabel = UILabel()
myLabel.translatesAutoresizingMaskIntoConstraints = false
myLabel.text = "HELLO"
myLabel.textColor = UIColor.white
circle.addSubview(myLabel)
// Setup constraints
myLabel.centerXAnchor.constraint(equalTo: circle.centerXAnchor).isActive = true
myLabel.centerYAnchor.constraint(equalTo: circle.centerYAnchor).isActive = true
I have attempted to mask my circle by using:
circle.mask = myLabel
This, however, results in the opposite effect I am after (my text is not a cut-out in the UIView, but rather, my text is now black). Where might I be going wrong to accomplish this effect?
Masks work in an opposite fashion, when the color on your mask is not transparent then it will show the content in that pixels position and when the pixels are transparent then it will hide the content.
Since you can't achieve this using UILabel you need to use something else as a mask, such as a CALayer.
If you lookup "UILabel see through text" you should find results similar to this which basically also applies to you (with some changes).
Instantiate your CircleView, then instantiate a CATextLayer and use this as a mask for your UIView

swift - change color of top UIToolbar border

I'm trying to change the color of the top border on a UIToolbar.
I tried:
layer.borderWidth = 1
layer.borderColor = UIColor(r: 250, g: 250, b: 250).CGColor
That didn't work.
Suggestions? Thank you
I've done it using this code:
class ViewController: UIViewController {
#IBOutlet weak var toolBar: UIToolbar!
override func viewDidLoad() {
super.viewDidLoad()
// the layer with the width of the device
// and height of 0.5 px
let topBorder = CALayer()
topBorder.frame = CGRectMake(0, 0, view.frame.size.width, 0.5)
topBorder.backgroundColor = UIColor.redColor().CGColor
// adding the layer to the top
// of the toolBar
toolBar.layer.addSublayer(topBorder)
}
}
Result:
Source: https://blog.adamcooke.io/set-the-top-border-colour-of-a-uinavbar-d9035c6b4fdb#.f37molpsj
If you don't like its color, and as it isn't possible to change it, fastest hack is to get rid of that hairline - It is not actually a border, it's a shadow.
toolbar.clipsToBounds = true
OR:
toolbar.layer.shadowOpacity = 0
Or maybe you are able to change its shadow image:
UITabbar.appearance().shadowImage = UIImage.colorForNavBar(.red)
UIColor works between 0 and 1 so for example:
If you want 250 as your red value you need to do 250/255. I had this same problem and found that just by adding the /255 after the value the color works as expected.
The /255 creates the value in the proper range. You could also do the division and put in the decimal approximation.
If you need any more help or clarification please let me know.
You need to set RGB colours divided by 255.0 to get a 0 to 1 colour.
For example:
layer.borderWidth = 1
layer.borderColor = UIColor(r: 250/255, g: 250/255, b: 250/255).CGColor
You can use:
- (void)setToolbarLineWith:(UIColor *)color
{
for(UIView *v in self.navigationController.toolbar.subviews){
if([NSStringFromClass([v class]) isEqualToString:#"_UIBarBackground"])
{
for(UIView *w in v.subviews){
if([NSStringFromClass([w class]) isEqualToString:#"UIImageView"])
{
[w setBackgroundColor:color];
}
}
}
}
}
and run with:
[self setToolbarLineWith:[UIColor redColor]];
That's actually a shadow image, so just create some 1 pixel image with necessary color and use
[toolbar setShadowImage:<your image> forToolbarPosition:UIBarPositionAny];