How to get the color of a pixel in an UIView?

Here is more efficient solution: // UIView+ColorOfPoint.h @interface UIView (ColorOfPoint) – (UIColor *) colorOfPoint:(CGPoint)point; @end // UIView+ColorOfPoint.m #import “UIView+ColorOfPoint.h” #import <QuartzCore/QuartzCore.h> @implementation UIView (ColorOfPoint) – (UIColor *) colorOfPoint:(CGPoint)point { unsigned char pixel[4] = {0}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); CGContextTranslateCTM(context, -point.x, -point.y); [self.layer renderInContext:context]; … Read more

Having trouble getting UIView sizeToFit to do anything meaningful

The documentation is pretty clear on this. -sizeToFit pretty much calls -sizeThatFits: (probably with the view’s current size as the argument), and the default implementation of -sizeThatFits: does almost nothing (it just returns its argument). Some UIView subclasses override -sizeThatFits: to do something more useful (e.g. UILabel). If you want any other functionality (such as … Read more

iOS: UIView subclass init or initWithFrame:?

The designated initializer is the one that all the other initializers must call. UIView and subclasses are a little unusual in that they’ve actually got two such initializers: -initWithFrame: and -initWithCoder:, depending on how the view is created. You should override -initWithFrame: if you’re instantiating the view in code, and -initWithCoder: if you’re loading it … Read more

iPhone – Draw transparent rectangle on UIView to reveal view beneath

You have to override the top view’s drawRect method. So, for example, you might create a HoleyView class that derives from UIView (you can do that by adding a new file to your project, selecting Objective-C subclass, and setting “Subclass of” to UIView). In HoleyView, drawRect would look something like this: – (void)drawRect:(CGRect)rect { // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)