ios

iOS – Just a quick way to create a shadow on any view

Jeroen Leenarts

Sometimes you would want a shadow on a view.

Easiest and quickest way is to just add it on the view’s layer:

-(void)loadView {
    CGRect frame = [[UIScreen mainScreen] applicationFrame];
    
    self.view = [[UIView alloc] initWithFrame:frame];
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.view.backgroundColor = [UIColor blackColor];
    
    UIView *glowView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width /2 -10, frame.size.height /2 -30, 20, 60)];
    glowView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | 
                                    UIViewAutoresizingFlexibleTopMargin |
                                    UIViewAutoresizingFlexibleLeftMargin |
                                    UIViewAutoresizingFlexibleRightMargin;
    
    glowView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:glowView];
    
    //Setup the shadow on the view's CALayer.
    CALayer *viewLayer = glowView.layer;
    viewLayer.shadowOffset = CGSizeMake(0, 0);
    viewLayer.shadowColor = [[UIColor yellowColor] CGColor];
    viewLayer.shadowPath = [UIBezierPath bezierPathWithRect:glowView.bounds].CGPath;
    viewLayer.shadowRadius = 10.0f;
    viewLayer.shadowOpacity = 1.0f;
 
    //Let's animate it while we're at it.
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
    animation.duration = 0.5f;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    animation.fromValue = [NSNumber numberWithFloat:1.0];
    animation.toValue = [NSNumber numberWithFloat:0.0];
    animation.autoreverses = YES;
    animation.repeatCount = HUGE_VALF;
    [viewLayer addAnimation:animation forKey:@"shadowOpacity"];
}

I must admit, this is kind of basic stuff. But it seems a lot of people actually forget about the fact that all UIView subclasses are based on Core Animation CALayers.

See the source code https://github.com/xebia/ios-DemoForBlog and try the example, the interesting bits about this example are all contained within the fourth tab of the application, it’s the XSDFourthViewController in the code.

iOS – Voiceover and view picking

Jeroen Leenarts

Something that might interest the developers out there working with accessibility on iOS.

If you have strange behavior, as in, being unable to (partially) pick an accessibility frame by just dragging your finger over the screen, I might be able to answer just why.

As it turns out. VoiceOver and sub views being out of bounds of their parent’s view bounds don’t really mix. Read more

iOS – Animation glitch example

Jeroen Leenarts

A short while ago we were running into an interesting animation glitch. The actual solution is quite simple.

Here’s what the glitch was about. A table view could be toggled into an edit mode. On performing this toggle a label would be animated out of the view and hidden. The strange thing was, that this label was resizing it’s font size right the second before the actual animation started.

Fortunately we were able to fix this problem. Read more

iOS – NSFetchedResultsController example with CoreData manipulation through an NSOperation

Jeroen Leenarts

Recently I started working for Xebia and what better way to introduce myself with a nice blogpost and some free code and some explanation to go along with it.

To get you started: here is the code. It’s on GitHub so don’t be afraid to send in suggestions and whatnot. Read more

iOS + XCode 4 + GHUnit = Mobile TDD+Continuous testing part 2 of n

Robert van Loghem

Last time I explained why I think doing TDD for mobile is imperative, and why I do it. But now it’s time to get technical, and explain to you how to set up, GHUnit in XCode 4 and run unit tests, not only in the iPhone and iPad simulator but also on your own physical device!, it’s in text and images but also in video form on YouTube.

Note, if you want to know why i chose GHUnit over OCUnit, just scroll down to the end of the post.

 Read more

Why TDD+ Continuous testing is imperative for mobile apps (part 1 of n)

Robert van Loghem

Since a couple of months I’ve been developing mobile applications, some are for the business at home (girlfriend-shopping-list app that actually works and augmented reality garden iPad app) and some are for work. I have experienced that TDD and Continuous testing (Test Driven Development) is a way of working that leads to fewer bugs and regression problems and better design in my software, it’s my preferred way of programming, not testing.

Mobile TDD is imperitive

And to start off, here’s how I benefit from doing TDD:

  1. Robust
  2. Better code design, no really!
  3. Find regression problems early on

and you can read more on TDD and Continuous testing here.

The thing is, writing a mobile app takes about 20% of the time it would take me to write a web+client+server based app. Which of-course is really nice, because I can write lots of apps. It also means that whenever i need to fix a bug or add new functionality, I need to have developed it in a TDD fashion, otherwise i cannot guarantee reliability. So let me explain why…

 Read more