uiview

UIView Background Color Always Black

做~自己de王妃 提交于 2020-01-12 02:42:07
问题 When I add a UIView to a View Controller programmatically I am not able to change the background color to any other color, it always remains black. - (void)drawRect:(CGRect)rect { // Drawing code self.backgroundColor = [UIColor blueColor]; UIBezierPath *path = [[UIBezierPath alloc] init]; [path moveToPoint:CGPointMake(100, 33)]; [path addLineToPoint:CGPointMake(200, 33)]; path.lineWidth = 5; [[UIColor redColor] setStroke]; [path stroke]; } When I comment drawrect: out and add self

How do I write a custom init for a UIView subclass in Swift?

限于喜欢 提交于 2020-01-11 14:48:53
问题 Say I want to init a UIView subclass with a String and an Int . How would I do this in Swift if I'm just subclassing UIView ? If I just make a custom init() function but the parameters are a String and an Int, it tells me that "super.init() isn't called before returning from initializer". And if I call super.init() I'm told I must use a designated initializer. What should I be using there? The frame version? The coder version? Both? Why? 回答1: The init(frame:) version is the default

How to create storyboard layout multiple views within header view iOS?

点点圈 提交于 2020-01-11 12:34:28
问题 I have created header UIView on storyboard view controller, now I need to create 4 views like below colored image Into that UIview base view. It should show for all devices. Need to adjust auto layout using iOS . 回答1: First set constraints to header view. Select header view and apply following constraints: Leading, top, trailing space and Height = 80 (for example) Once you apply constraints to header view then select all buttons at once : Hope this can help 回答2: Try this.. Now IOS 9 realse

Circular UIView with multiple coloured border working like a pie chart

六眼飞鱼酱① 提交于 2020-01-11 12:14:12
问题 I am trying to set a circular avatar of a player of a game with a piechart representation on the avatar's circular border. Player 1 - Wins 25% Lost 70% Drawn 5% cell.selectedPhoto.frame = CGRectMake(cell.selectedPhoto.frame.origin.x, cell.selectedPhoto.frame.origin.y, 75, 75); cell.selectedPhoto.clipsToBounds = YES; cell.selectedPhoto.layer.cornerRadius = 75/2.0f; cell.selectedPhoto.layer.borderColor=[UIColor orangeColor].CGColor; cell.selectedPhoto.layer.borderWidth=2.5f; cell.selectedBadge

Changing height of UIView in response to finger drag

ぐ巨炮叔叔 提交于 2020-01-11 04:43:12
问题 I understand that the title is a bit confusing so I'll try my best to explain it well. I have a UIView that has a fixed width of 100, and a variable height that starts at 0. What I want to be able to do is drag my finger from the base of the UIView, towards the top of the screen, and the UIView changes its height/extends to the position of my finger. If that's still to complicated just imagine it as a strip of paper being pulled out from under something. If you can help, that would be really

Check if UIView is displaying a UIAlertView

自闭症网瘾萝莉.ら 提交于 2020-01-11 03:13:05
问题 Is it possible to determine if the current UIView has a UIAlertView on display (other than setting a variable every time a UIAlertView is created). I'm thinking something along the lines of if ([self.view.subviews containsObject:UIAlertView]) { ... } But that obviously doesn't work. 回答1: This will not work in iOS7 and above. [alertView Show] adds subview on main window I guess. for (UIWindow* window in [UIApplication sharedApplication].windows){ for (UIView *subView in [window subviews]){ if

Why does my UIImage take up so much memory?

冷暖自知 提交于 2020-01-10 19:33:11
问题 I have a UIImage that I'm loading into one of my app's views. It is a 10.7 MB image, but when it loads in the app, the app's resource usage suddenly jumps by 50 MB. Why does it do this? Shouldn't memory used increase by only about 10.7MB? I am certain that loading the image is what causes the jump in memory usage because I tried commenting these lines out and the memory usage went back to around 8 MB. Here's how I load the image: UIImage *image = [UIImage imageNamed:@"background.jpg"]; self

How to Animate CoreGraphics Drawing of Shape Using CAKeyframeAnimation

ⅰ亾dé卋堺 提交于 2020-01-10 10:51:03
问题 I am trying to animate the drawing of a UIBeizerPath (in my example a triangle) in a UIView subclass. However, the entire subview is animating instead of the shape. Is there something I am missing with the animation? - (void)drawRect:(CGRect)rect { CAShapeLayer *drawLayer = [CAShapeLayer layer]; drawLayer.frame = CGRectMake(0, 0, 100, 100); drawLayer.strokeColor = [UIColor greenColor].CGColor; drawLayer.lineWidth = 4.0; [self.layer addSublayer:drawLayer]; UIBezierPath *path = [UIBezierPath

how to set a background image as colorWithPatternImage in swift

安稳与你 提交于 2020-01-10 06:48:08
问题 My questions is, is it possible to have a UIView display an image, and if so, how so I do it? All I can find is the colorwithpatternImage which no longer works with swift. The code I am trying to use now is: self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; Thanks in advance for your answers! 回答1: Refer to the UIColor documentation. In Swift, you have to call a convenience initializer. This is because in Swift, all Objective-C class methods

how can I get the scale factor of a UIImageView who's mode is AspectFit?

放肆的年华 提交于 2020-01-09 19:16:05
问题 how can I get the scale factor of a UIImageView who's mode is AspectFit? That is, I have a UIImageView with mode AspectFit. The image (square) is scaled to my UIImageView frame which is fine. If I want to get the amount of scale that was used (e.g. 0.78 or whatever) how can I get this directly? I don't want to have to compare say a parent view width to the UIImageView width as the calculation would have to take into account orientation, noting I'm scaling a square image into a rectangular