Make Background of UIView a Gradient Without Sub Classing

You can use +[UIColor colorWithPatternImage:] to produce a patterned background. Example (bring your own CGGradient): // Allocate color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Allocate bitmap context CGContextRef bitmapContext = CGBitmapContextCreate(NULL, 320, 480, 8, 4 * 320, colorSpace, kCGImageAlphaNoneSkipFirst); //allocate myGradient CGFloat locationList[] = {0.0f, 1.0f}; CGFloat colorList[] = {0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, … Read more

Rotating a view in layoutSubviews

The problem with the code in the question seems to be that the transformations keep getting added to each other. In order to fix this, the solution is to reset the transformations every time, that is, set it to the identity transform. rotationView.transform = CGAffineTransformIdentity Here is a partial implementation that shows the key parts. … Read more

Call protected method from a subclass of another instance of different packages

Don’t know the rationale, but JLS confirms this in 6.6.2. Details on protected Access (emphasis mine): A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object. So: package P2; public class P2 { … Read more

Why subclass in another package cannot access a protected method?

Protected methods can only be accessible through inheritance in subclasses outside the package. And hence the second approach tryMeProtected(); works. The code below wont compile because we are not calling the inherited version of protected method. Class1 c = new Class1(); c.tryMeProtected(); // ERROR: tryMeProtected() has protected access in Class1 Follow this stackoverflow link for … Read more

Swift + CoreData: Cannot Automatically Set Optional Attribute On Generated NSManagedObject Subclass

The optional checkbox in the Core Data Model Editor has been existing before Swift and its optionals where introduced. Apple states about it in its Core Data Programming Guide: You can specify that an attribute is optional — that is, it is not required to have a value. In general, however, you are discouraged from … Read more