UIRefreshControl uses a very large spinner:
I'd like to resize it (the frame of the spinner, not the pull-down length!) to look more like this:
I can't see anything in the reference docs about how do this, and though it inherits from UIView, setting the frame doesn't work (possibly because I'm using AutoLayout?)
let refreshControl = UIRefreshControl()
refreshControl.frame = CGRect.init(x: 0, y: 0, width: 32, height: 32)
Simply use refreshControl.transform = CGAffineTransformMakeScale(0.5, 0.5);
No need to import QuartzCore or doing whatever else.
It's easy. Just select from the inspector:
I think you use a large one.
Also you can do this:
import QuartzCore
activityIndicator.transform = CGAffineTransformMakeScale(0.75, 0.75);
This will create an activity indicator 15px wide
Update: Swift 5
refreshControl.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
Related
Is there anyway to create a NSButton with rounded corners and background color without subclassing it. I have this code and it does not do anything.
let directionsButton = NSButton(frame: NSRect(x: 0, y: 0, width: 100, height: 60))
directionsButton.title = "Click Me!"
directionsButton.layer?.cornerRadius = 10
directionsButton.layer?.masksToBounds = true
directionsButton.layer?.backgroundColor = NSColor.blue.cgColor
To enable the CoreAnimation layer you have to insert this line before using it
directionsButton.wantsLayer = true
Edit: To be able to change the color you have to draw a borderless button. Add
directionsButton.isBordered = false
Simply as the title says, I'm trying to center one Activity Indicator on the center of my View by doing that:
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
self.view.addSubview(activityIndicator)
but I end up with this result:
the problem persists within all view controllers in this app, except for the last one, that really centers it as you can see:
Xcode 10 / Swift 4
It can be the hight of the tab bar is disturbing. anyways,
If your code (.center) doesn't work, try this:
activityIndicator.frame = CGRect.init(x: view.frame.size.width / 2, y: view.frame.size.height / 2, width: 0, height: 0)
If it still doesn't work, change y: view.frame.size.height / 2 - "THE HIGHT OF TAB BAR".
I am wondering if I can use UI elements like UIButton, UILabel in an augmented reality app with ARKit.
If you are also interested in transparency modes for that UIView subclasses try my sample https://github.com/erikhric/ar-menu
You can use different blending modes. I guess .alpha will work for your purposes.
Yes, you can use UIKit elements by adding them to a UIView that's positioned above the view displaying the AR scene (ARSKView or ARSCNView).
If you create a new project in Xcode and select the "Augmented Reality App" template, you can see that the AR content is just a view like any other UIKit view.
What worked best for me
in main.storyboard:
- delete SceneView
- add regular UIView
- add ARKit SceneKit View on top of that
- then you can add buttons, etc.
Yes you can place UI elements on top of the ARSKView or ARSCNView displaying the AR scene:
let scanningPanel = UIImageView()
scanningPanel.backgroundColor = UIColor(white: 0.33, alpha: 0.6)
scanningPanel.layer.masksToBounds = true
scanningPanel.frame = CGRect(x: -2,
y: self.sceneView.frame.height-270,
width: 178,
height: 50)
scanningPanel.layer.cornerRadius = 10
let scanInfo = UILabel(frame: CGRect(x: 8,
y: self.sceneView.frame.height-268,
width: 160,
height: 45))
scanInfo.textAlignment = .left
scanInfo.font = scanInfo.font.withSize(15)
scanInfo.textColor = UIColor.white
scanInfo.text = "SCAN A SURFACE"
Adding:
self.sceneView.addSubview(scanningPanel)
self.sceneView.addSubview(scanInfo)
Removing:
if(scanInfo.isDescendant(of: self.sceneView)) {
scanInfo.removeFromSuperview()
}
You can insert content of any view on a plane in ARKit like this:
let plane = SCNPlane(width: sceneView.bounds.width/3000,
height: sceneView.bounds.height/3000)
plane.firstMaterial?.diffuse.contents = self.anyView`
Gestures and taps are automatically sent to that view.
Try my example.
Just as the following image, how to draw that black line?
I want the line to be drawn on layer, not on another view.
The problem I got is how to locate the bottom. Thanks for any suggestion.
Here i have used textfield same way you can use for button also
let borderOld = CALayer()
let width = CGFloat(1.5)
borderOld.frame = CGRect(x: 0, y: txtField.frame.size.height - width, width: txtField.frame.size.width, height: txtField.frame.size.height)
borderOld.borderWidth = width
txtField.layer.masksToBounds = true
txtField.layer.addSublayer(borderOld)
I have written a custom graph UIView subclass, and I use it to graph some basic data, and insert some user-defined data. As a final step, I'd like to add a UILabel on top of the graph with the user-defined data-point called out.
I highlight the point, and then create and add the UILabel:
if(graphPoints[i] == highlightPoint){
var point2 = CGPoint(x:columnXPoint(i), y:columnYPoint(graphPoints[i]))
point2.x -= 8.0/2
point2.y -= 8.0/2
let circle2 = UIBezierPath(ovalInRect:
CGRect(origin: point2,
size: CGSize(width: 8.0, height: 8.0)))
highlightColor.setFill()
highlightColor.setStroke()
circle2.fill()
let circle = UIBezierPath(ovalInRect:
CGRect(origin: point,
size: CGSize(width: 5.0, height: 5.0)))
UIColor.whiteColor().setFill()
UIColor.whiteColor().setStroke()
circle.fill()
var pointLabel : UILabel = UILabel()
pointLabel.text = "Point = \(graphPoints[i])"
pointLabel.frame = CGRectMake(point2.x, point2.y, 100, 50)
self.addSubview(pointLabel)
} else {
let circle = UIBezierPath(ovalInRect:
CGRect(origin: point,
size: CGSize(width: 5.0, height: 5.0)))
UIColor.whiteColor().setFill()
UIColor.whiteColor().setStroke()
circle.fill()
}
This looks like it should work, but the UILabel is added twice. What am I doing wrong?
This code is probably in drawRect. You're doing subview-adding in drawRect which is incorrect. drawRect gets called at least twice as the view appears, and perhaps many times after that.
You should be overriding some early lifecycle method, like awakeFromNib() or the constructor. In that, construct your label and add it as a child view. This way the addSubView() happens once as it should. The label will be invisible having no contents, so don't worry about that.
In drawRect, just update all the necessary attributes of the label including the frame.
If you find you're actually needing lots of text "labels" that come and go, different quantity for every graph, you don't really want UILabels as subviews after all. Consider directly drawing text on screen with someString.drawAtPoint(...)