cgrect

How to add rounded corners to a UIView with gradient applied?

蹲街弑〆低调 提交于 2020-01-03 05:58:28
问题 I've written custom subclass of UIView that draws a gradient inside of it: import UIKit @IBDesignable class PlayerCellView: UIView { var startColor: UIColor = UIColor(red:0.20, green:0.75, blue:1.00, alpha:1.00) var endColor: UIColor = UIColor(red:0.07, green:0.42, blue:1.00, alpha:1.00) override func draw(_ rect: CGRect) { let context = UIGraphicsGetCurrentContext() let colors = [startColor.cgColor, endColor.cgColor] let locations : [CGFloat] = [0.0, 1.0] let gradient = CGGradient

Point inside a rotated CGRect

半腔热情 提交于 2020-01-01 05:36:22
问题 How would you properly determine if a point is inside a rotated CGRect/frame? The frame is rotated with Core Graphics. So far I've found an algorithm that calculates if a point is inside a triangle, but that's not quite what I need. The frame being rotated is a regular UIView with a few subviews. 回答1: Let's imagine that you use transform property to rotate a view: self.sampleView.transform = CGAffineTransformMakeRotation(M_PI_2 / 3.0); If you then have a gesture recognizer, for example, you

How to resize UITextView while typing inside it?

好久不见. 提交于 2019-12-31 12:56:10
问题 I'm creating a comment section much like the one Facebook uses for it's messaging section in it's iOS app. I want the UITextView to resize the height so the text I'm typing fits inside it rather than you having to scroll to see the text that overflows. Any ideas how I might go about doing this? I've looked into maybe using a CGRect that is assigned to the size and height of the text view which then matches the content size: CGRect textFrame = textView.frame; textFrame.size.height = textView

Difference between frame.size.width and frame.width

梦想的初衷 提交于 2019-12-29 06:45:07
问题 I was writing a program in swift and just now I noticed that I can directly access a CGRect frame's width and height properties directly without using the CGSize width and height. That is I am now able to write a code like this. @IBOutlet var myView: UIView! override func viewDidLoad() { super.viewDidLoad() var height = myView.frame.height var height1 = myView.frame.size.height } In Objective C, when I tried to write the same code, the line height = view.frame.height is throwing an error. Can

Find Rectangle contains Point from array of rectangles

社会主义新天地 提交于 2019-12-25 10:58:10
问题 I have an array of rectangles. Trying to find out a rect which contains given point. I can iterate this array and use CGRectContainsPoint to find the rect contains this point. Pseudo code is as follows CGRect rectContainingPoint; for (CGRect rect in arrayOfRects) { if(CGRectContainsPoint(rect, point)) { rectContainingPoint = rect; break; } } I feel this may not be elegant solution in terms of performance if my array is so large where I have to iterate large array. Can someone help me if there

why UITextView draws text in bad frame after resizing?

醉酒当歌 提交于 2019-12-23 13:06:23
问题 I'm stuck with some kind of magic: when I try to change UITextView frame (in this case with UISlider), text is drawn in some other (smaller) area than frame (resizing multiple times). The funny thing is that if we slide fast enough when trying to make frame bigger, text is drawn in pretty correct area. Can somebody explain why? I tried to layout, autoresize, set content size and bounds, but nothing works. - (void)viewDidLoad { [super viewDidLoad]; _textView = [[UITextView alloc] initWithFrame

How to combine CGRects with each other in Swift

Deadly 提交于 2019-12-23 10:15:36
问题 I was wondering if there was any way to combine a CGRect with another CGRect to get a new CGRect. Does swift have any preset functionality to do this or is there another way of achieving this? 回答1: let rect1 = CGRect(x: 0, y: 0, width: 100, height: 100) let rect2 = CGRect(x: 40, y: 40, width: 150, height: 150) CGRectUnion(rect1, rect2) // {x 0 y 0 w 190 h 190} See for more: https://developer.apple.com/documentation/coregraphics/cggeometry https://developer.apple.com/documentation/coregraphics

MonoTouch convert color UIImage with alpha to grayscale and blur?

僤鯓⒐⒋嵵緔 提交于 2019-12-22 04:07:56
问题 I am trying to find a recipe for producing a a blurred grayscale UIImage from a color PNG and alpha. There are recipes out there in ObjC but MonoTouch does not bind the CGRect functions so not sure how to do this. Any ideas? Here is one ObjC example of grayscale: (UIImage *)convertImageToGrayScale:(UIImage *)image { // Create image rectangle with current image width/height CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); // Grayscale color space CGColorSpaceRef

How to get frame size after autoresize is done

倾然丶 夕夏残阳落幕 提交于 2019-12-21 17:09:13
问题 I wonder, how and when (viewDidLoad, viewWillAppear, viewDidAppear) can I get a UIViews frame size that was autoresized to fit its partent view? 回答1: It's not clear from your question why you want it but I imagine it is to layout your sub views. Luckily Apple knew you would want to do that and implemented -(void)layoutSubViews see this: When is layoutSubviews called? 回答2: I tried layoutSubviews , but it gets called more than once which is a problem when I need the auto sized frame in order to

Child content view controller view has wrong bounds size from Storyboard?

筅森魡賤 提交于 2019-12-21 17:07:32
问题 This document outline from my sample Storyboard shows what I'm working with. I have a custom container view controller and two content view controllers connected via embed segues. Here is the storyboard itself. ZetaViewController has to create some programmatic views (within ZetaView, of course). I noticed when I was centering these programmatically created views they seemed really off center. ZetViewController is centering things by examining self.view.bounds.size.height and self.view.bounds