Styling of NSTextField - swift

How to make border and style of NStextField like that (except icon on the right)? Is it custom or built-in?

Set new CALayer and play with isBezeled and isBordered properties before setting colors.
let field = NSTextField()
field.layer = CALayer()
field.wantsLayer = true
field.isBezeled = false
field.isEditable = true
field.isBordered = true
field.backgroundColor = NSColor.white
field.layer?.borderColor = NSColor.gray.cgColor
field.layer?.backgroundColor = NSColor.white.cgColor
field.layer?.borderWidth = 1
field.layer?.cornerRadius = 5

Related

How to make Height and Width of ScrollView Still The same Before ZoomIn on UIImage?

Hello All iOS developer I'm new at iOS development. at the moment I work In the case I want to Zoom Picture, I use UIImageView in UIScrollView. Everything is Ok on ScrollView Height and Width but when I try to ZoomIn and ZoomOut to make to current Size of Image the UIScrollView has Increase the Height and Width. and I try to find out the solution but it's work.I need some help.thank you in advance.
This's The Problem
Here is my code
override func viewDidLoad() {
super.viewDidLoad()
initializeLanguages()
checkForm()
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.bounces = false
scrollView.delegate = self
lblRetake.textColor = TrueColor.trueColorbrand()
updateZoom()
scrollView.layer.cornerRadius = 10
scrollView.layer.masksToBounds = true
setShadowView(view: viewContainer)
imageView.isUserInteractionEnabled = true
addViewGesture()
displayImage()
}
//MARK: ZoomOut/ZoomIn Image
func updateZoom() {
let fwidth = self.imageView.image?.size.width ?? 0
let fheight = self.imageView.image?.size.height ?? 0
var minZoom = min(fwidth, fheight);
if (minZoom > 1) {
minZoom = 1;
}
self.scrollView.minimumZoomScale = minZoom;
self.scrollView.zoomScale = minZoom;
scrollView.maximumZoomScale = 10.0
}

UILabel with Border and background Issue

Here is the code I have for UILabel
descriptionText.layer.cornerRadius = 8
descriptionText.layer.borderColor = UIColor.lightGray.cgColor
descriptionText.layer.borderWidth = 2
descriptionText.text = ""
descriptionText.layer.shadowOffset = CGSize(width: -10, height: -10)
descriptionText.layer.shadowRadius = -5.0
descriptionText.backgroundColor = .white
descriptionText.textColor = .black
descriptionText.numberOfLines = 0
descriptionText.lineBreakMode = .byWordWrapping
However This is what it looks like
Why is the Corner Not Transparent or how do you make what is outside the border transparent
Thanks in advance
You need to hide everything outside of the cornerRadius by setting .clipsToBounds on the label to true. Problem is that if you do this you will lose the shadow, as this is outside the bounds as well. Try this:
Place your label inside a container view, constrain the label to the container edges, and create an outlet to it. Then try the following code:
containerView.borderColor = UIColor.lightGray.cgColor
containerView.layer.borderColor = UIColor.lightGray.cgColor
containerView.layer.borderWidth = 2
containerView.layer.shadowOffset = CGSize(width: -10, height: -10)
containerView.layer.shadowRadius = -5.0
containerView.backgroundColor = UIColor.clear
descriptionText.text = "Testing"
descriptionText.cornerRadius = 8
descriptionText.clipsToBounds = true // or descriptionText.layer.masksToBounds = true
descriptionText.backgroundColor = .white
descriptionText.textColor = .black
descriptionText.numberOfLines = 0
descriptionText.lineBreakMode = .byWordWrapping

How to add label to SCNNode?

I’m trying to add a label to an SCNNode. So far I’ve managed to set a SKLabelNode as the material for the SCNNode. It sort of works, I can the SCNNode becomes the background colour of the SKLabelNode but I can’t see the text. Sometime I can see a red haze (the text colour is red) but no readable text.
I also tried setting the material as a UIView and adding a UiLabel as a sub view. Again it sets as I can the whole SCNNode becomes the background colour of the UiLabel but I can’t see any text.
var block = SCNNode()
var spriteScene = SKScene()
var Lbl = SKLabelNode()
lbl.text = “Hello World”
lbl.color = blue (playground colour literal)
lbl. = 2 //I tried various numbers
lbl.fontColor = SKColor.red
spriteScene.addChild(lbl)
I got it after some hit and trial. I had to try different values before I got these size, scale and rotation to display the label as I want.
note: My node here is SCNPlane with 0.3 width and 0.2 height, so size of SKScene and rectangle and position of label are hard coded accordingly.
func addLabel(text: String){
let sk = SKScene(size: CGSize(width: 3000, height: 2000))
sk.backgroundColor = UIColor.clear
let rectangle = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 3000, height: 2000), cornerRadius: 10)
rectangle.fillColor = UIColor.black
rectangle.strokeColor = UIColor.white
rectangle.lineWidth = 5
rectangle.alpha = 0.5
let lbl = SKLabelNode(text: text)
lbl.fontSize = 160
lbl.numberOfLines = 0
lbl.fontColor = UIColor.white
lbl.fontName = "Helvetica-Bold"
lbl.position = CGPoint(x:1500,y:1000)
lbl.preferredMaxLayoutWidth = 2900
lbl.horizontalAlignmentMode = .center
lbl.verticalAlignmentMode = .center
lbl.zRotation = .pi
sk.addChild(rectangle)
sk.addChild(lbl)
let material = SCNMaterial()
material.isDoubleSided = true
material.diffuse.contents = sk
node.geometry?.materials = [material]
node.geometry?.firstMaterial?.diffuse.contentsTransform = SCNMatrix4MakeScale(Float(1), Float(1), 1)
node.geometry?.firstMaterial?.diffuse.wrapS = .repeat
node.geometry?.firstMaterial?.diffuse.wrapS = .repeat
}

remove zero line from ios charts

I've created a simple small chart using (https://github.com/danielgindi/Charts), where i'm trying to remove everything beside the line itself, but i can't seem to remove the bottom zero axis. i've looked through the documentation, but cannot seem to remove it?
chart
class CellChartView: UIView {
var lineChart: LineChartView!
override init(frame: CGRect) {
super.init(frame: frame)
self.lineChart = LineChartView()
lineChart.backgroundColor = Color.lightTheme.value
lineChart.translatesAutoresizingMaskIntoConstraints = false
self.lineChart.chartDescription?.text = ""
self.lineChart.isUserInteractionEnabled = false
self.lineChart.legend.enabled = false
self.lineChart.minOffset = 0
self.lineChart.drawBordersEnabled = false
self.lineChart.drawGridBackgroundEnabled = false
self.lineChart.autoScaleMinMaxEnabled = true
self.lineChart.rightAxis.enabled = false
self.lineChart.leftAxis.enabled = false
self.lineChart.leftAxis.drawAxisLineEnabled = false
self.lineChart.leftAxis.axisLineColor = UIColor.green
self.lineChart.xAxis.drawLabelsEnabled = false
self.lineChart.xAxis.drawGridLinesEnabled = false
self.lineChart.xAxis.labelPosition = .bottom
self.lineChart.xAxis.drawLimitLinesBehindDataEnabled = false
self.lineChart.xAxis.enabled = false
self.lineChart.xAxis.axisLineColor = UIColor.clear
self.addSubview(self.lineChart)
lineChart.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
lineChart.topAnchor.constraint(equalTo: self.topAnchor, constant: -1).isActive = true
lineChart.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true
lineChart.heightAnchor.constraint(equalTo: self.heightAnchor).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setChartData(values: [Double], dates: [String]) {
var yValues : [ChartDataEntry] = [ChartDataEntry]()
for i in 0 ..< dates.count {
yValues.append(ChartDataEntry(x: Double(i + 1), y: values[i]))
}
let data = LineChartData()
let ds = LineChartDataSet(values: yValues, label: "Date")
ds.drawCirclesEnabled = false
ds.lineWidth = 1
ds.drawValuesEnabled = false
if (values.first ?? 0.0 > values.last ?? 0.0) {
ds.setColor(Color.redColor.value)
} else {
ds.setColor(Color.greenColor.value)
}
data.addDataSet(ds)
data.setDrawValues(false)
self.lineChart.data = data
}
}
If you just want to hide the xAxis, then I see two ways:
You could disable the xAxis xAxis.enabled = false
Or set the xAxis line color to transparent xAxis.axisLineColor = UIColor.clear
If you want to hide the horizontal and vertical lines being drawn through the center when you have disabled all grid lines and just want an X-Axis line as shown above in your drawing
lineChartDataSet.highlightColor = NSUIColor.clear
myLineChartView.xAxis.drawAxisLineEnabled = true
myLineChartView.xAxis.drawGridLinesEnabled = false
myLineChartView.xAxis.drawLabelsEnabled = false
myLineChartView.leftAxisAxis.drawAxisLineEnabled = false
This will just hide the horizontal and vertical lines while giving you the freedom to draw a line through X-Axis or Y-Axis.
If you just want to hide background gridlines
Just do
self.chartView?.leftAxis.drawGridLinesEnabled = false
self.charView?.xAxis.drawGridLinesEnabled = false
It will remove background grids for both axis. like that

How to align both right and left axis in the same line using ios-charts?

I have the following line chart with 2 datasets.
One data set is dependent on the left yAxis the other one on the right yAxis.
Now i want them both to have the zero value in the same line.
The other values are ok to not be aligned.
How can i do that?
Code:
let speedLine = LineChartDataSet(values: speedEntries, label: "Speed")
speedLine.colors = [UIColor.white]
speedLine.drawCirclesEnabled = false
speedLine.axisDependency = .left
let powerLine = LineChartDataSet(values: powerEntries, label: "Power")
powerLine.colors = [UIColor.green]
powerLine.drawCirclesEnabled = false
powerLine.axisDependency = .right
let data = LineChartData()
data.addDataSet(speedLine)
data.addDataSet(powerLine)
chartView.data = data
chartView.xAxis.labelTextColor = UIColor.white
chartView.xAxis.labelCount = 20
chartView.leftAxis.labelTextColor = UIColor.white
chartView.rightAxis.labelTextColor = UIColor.green
chartView.legend.textColor = UIColor.white
chartView.rightAxis.axisMinimum = -80.0
chartView.chartDescription?.text = ""
Since you have:
chartView.rightAxis.axisMinimum = -80.0
You might need to do this as well:
chartView.leftAxis.axisMinimum = -80.0
I think there is still no resolution for this problem but we can still hide yAxis right side.
let yAxisLeft = chartView.leftAxis
yAxisLeft.drawGridLinesEnabled = true
yAxisLeft.gridColor = UIColor(hex: "DCE5EE")
yAxisLeft.labelFont = Theme.Font.main(ofSize: 9, weight: .regular)
yAxisLeft.labelXOffset = 2
yAxisLeft.labelTextColor = Theme.Color.white
yAxisLeft.axisLineColor = UIColor(hex: "DCE5EE")
yAxisLeft.drawAxisLineEnabled = false
yAxisLeft.labelCount = 4
yAxisLeft.axisMinLabels = 1
yAxisLeft.enabled = true
yAxisLeft.axisMinimum = 0
let yAxisRight = chartView.rightAxis
yAxisRight.drawGridLinesEnabled = false
yAxisRight.labelFont = Theme.Font.main(ofSize: 9, weight: .regular)
yAxisRight.labelXOffset = -2
yAxisRight.labelTextColor = Theme.Color.white
yAxisRight.drawAxisLineEnabled = false
yAxisRight.labelCount = 4
yAxisRight.axisMinLabels = 1
yAxisRight.enabled = true
yAxisRight.axisMinimum = 0
This is the final result: