How to write test cases for drawing text / string in a box? - iphone

I am drawing strings in a rectangular frame. The string is drawing perfectly. Now I need to write test cases using sentesting kit. I have no ideas from where I should start. For help I have also seen the iPhone sample calculator application
But still out of sorts.
Any body having ideas please help.
Thanks,
Madhup

GUI drawing code is often hard to test. In your case it depends how you draw your string. If you draw it into a custom view by using the -(void)drawRect: method and therein just drawing your NSString (I suppose), then I do not think your can test that this drawing happend properly.
If you use a separate view like a UITextLabel you could test for its existance by using STAssertNotNil. You could also check the proper positioning by checking the view's bounds.
If you need more help, please be a bit more specific and adding clean code would help.

Related

UITableViewCell Background stretching

I have a problem in Swift with UITableViewCell background image. Let's say that it shows quite fine one iPhone5 but on iPhone 6Plus it is stretch and thus it looks bad. This is probably due to Aspect fill or something which I really couldn't manage to change and achieve what I want so would be the best if someone could poke sample code I am providing as well as image how it should look, so anyone can check it out and maybe give me some hint or tip or sample code or even fixed demo version.
So here it is:
Note that on left side there is a curve (like half a circle) around right side of icon. On bigger phones or tablet, that curve gets super stretch thus completely destroying the look.
Demo code link
Thanks all in advance for any help. I am pretty stuck with this one.
You can stretch an image while preserving the aspect ratio of a portion of that image using slicing. Xcode offers a graphical interface for doing this. The idea is that you decide what parts of the image are allowed to stretch and which aren't.
https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/chapters/SlicinganImage.html

Dragging/Resizing a UIImage on the Device

I'd like to allow a user to add a shape (which would just be a UIImage) onto some sort of canvas, then move and resize it on the screen but I'm not sure how to go about this. Ideally I'd like the basics of a drawing app which can use images from a user's device. Each shape would have an associated position, size and z-index.
The only thing I'm unsure of is how I'd create a bounding box (the one with four blue dots to allow resizing/moving). I have experience with UIKit, and would prefer to keep the majority of the app in this for the time being, but I get the feeling this type of thing might be better suited to Cocos2D or a similar framework.
If anyone has any pointers/open source code I can dig through it would be hugely appreciated.
I think you should look into CALayer, or even CAShapeLayer. I'm just starting to play with them, but I'm pretty sure you can easily get the functionality you want with either. Draw the border in the layer's drawLayer:inContext:. Check out the Quartz2d Guide path drawing section for the functions you need.

Increase the call-frequency for the touchesMoved-method

I am currently working on an app, which includes a paint function. It actually doesn't work that bad, but the problem is, that the refresh-rate or the frequency of the calls for the touchesMoved-method is too bad.
If you move the fingers fast over the screen, the lines get many edges and it doesn't look that good. So i thought about increasing the call-frequency for this method. Would that be a good and even possible solution for my problem?
Maybe you can help me with my problem. Thank you in advance.
Think about this approach: Look at Adobe's Ideas App on the AppStore. If touchesEnd, work with NSBezierPath to get a smoother look without edges. You basically store the points in touchesMoved in an array? So you got the points to insert in the Bezier Path functions. You have a edgy look while drawing but after releasing it looks kind of smooth. I did so in one of my projects and result is fairly okay.
(But there are many other approaches to build a drawing application.)
Demo App from Apple: Click here

how to add a repeating background in cocos2d

I am new in iphone and as well in cocos2d
I have some queries about a game i am working on it.
Actually i have a background with some trees and bushes.and i have an object which keeps on moving and my background of trees and bushes is static at the back. I want the application to repeat the background and it give me a look that my object is moving forward.
Can anybody Guide me please.
I also want to implement speed so also guide me that how can i change the speed of background repetition. so that it gives a look that my object is slow or fast
Thanks
waiting for your positive response.
Regards
sHaH
Work through this excellent tutorial:
http://www.raywenderlich.com/3857/how-to-create-dynamic-textures-with-ccrendertexture
It'll surely help you.
The section "Repeating Backgrounds" explains how to make a texture repeat and animate it.
In order to change the speed you can make PIXELS_PER_SECOND a dynamic variable.

iPhone: no way to draw on screen outside drawRect?

Is there a way to draw on the iPhone screen (on a UIView in a UIWindow) outside of that view's drawRect() method? If so, how do I obtain the graphics context?
The graphics guide mentions class NSGraphicsContext, but the relevant chapter seems like a blind copy/paste from Mac OS X docs, and there's no such class in iPhone SDK.
EDIT: I'm trying to modify the contents of the view in a touch event handler - highlight the touched visual element. In Windows, I'd use GetDC()/ReleaseDC() rather than the full cycle of InvalidateRect()/WM_PAINT. Trying to do the same here. Arranging the active (touchable) elements as subviews is a huge performance penalty, since there are ~hundred of them.
No. Drawing is drawRect:'s (or a CALayer's) job. Even if you could draw elsewhere, it would be a code smell (as it is on the Mac). Any other code should simply update your model state, then set yourself as needing display.
When you need display, moving the display code elsewhere isn't going to make it go any faster. When you don't need display (and so haven't been set as needing display), the display code won't run if it's in drawRect:.
I'm trying to modify the contents of the view in a touch event handler - highlight the touched visual element. In Windows, I'd use [Windows code]. … Arranging the active (touchable) elements as subviews is a huge performance penalty, since there are ~hundred of them.
It sounds like Core Animation might be more appropriate for this.
I dont think ull be able to draw outside drawRect...but to get the current graphic context all you do is CGContextRef c = UIGraphicsGetCurrentContext(); hope that helps.