cocoa-touch

NSDecimalNumber multiplication strangeness

血红的双手。 提交于 2020-01-11 06:01:19
问题 ExclusivePrice, quantity are both NSDecimalNumbers. NSDecimalNumber *price = [exclusivePrice decimalNumberByMultiplyingBy:quantity]; NSLog(@"%@ * %@ = %@", exclusivePrice, quantity, price); The result I get: 2010-04-05 00:22:29.111 TestApp[13269:207] 65 * 2 = -0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007169919476068871316457914368 What I expected: 2010-04-05 00:22:29.111 TestApp[13269:207] 65 * 2 = 130 Can anyone explain this please? Edit:

Loading a Localized UIImage

。_饼干妹妹 提交于 2020-01-11 05:23:29
问题 I need to load localized images in my iOS app, but also have to take into account that they might need to be the ...@2x kind. How can I do this? 回答1: Corrected Answer [UIImage imageNamed:@"TestImage"] looks first into Resources, if nothing found, it then looks in the lproj dir folders. So you only need to put the localized images into the right folder. Old Answer NSLocalizedString should do the trick. See Localizing String Resources. UIImage *img = [UIImage imageNamed:NSLocalizedString(@

NSString representation of fractions using unicode

与世无争的帅哥 提交于 2020-01-11 05:05:32
问题 I am trying to "nicely" display fractions in my iPhone application. Previously I have been using a tedious switch statement leading to hardcoded unicode characters for the vulgar fractions, but I have learnt about the unicode fraction slash character which, if I am understanding it correctly, should mean that I can create a string as follows: [NSString stringWithFormat:@"%i\u2044%i",numerator,denominator]; And the "renderer" will automatically print it with a smaller, superscriped numerator

Forcing UIAlertView into landscape mode

你。 提交于 2020-01-11 04:13:05
问题 I need to display a UIAlertView in landscape mode. I tried the obvious, setting the transform in the willPresentAlertView: delegate method to no avail: -(void) willPresentAlertView:(UIAlertView *)alertView { alertView.transform = CGAffineTransformMakeRotation(M_PI_2); } Any suggestions on how to fix this? 回答1: Have you tried in the didPresentAlertView ? - (void)didPresentAlertView:(UIAlertView *)alertView { // UIAlertView in landscape mode [UIView beginAnimations:@"" context:nil]; [UIView

touchesBegin & touchesMove Xcode Obj C Question

纵饮孤独 提交于 2020-01-11 04:00:24
问题 So I have my app working good when you press and drag along. I also have UIButtons set to Touch Down in Interface Builder. As well when you drag you need to drag from the outside of the UIButton. You cannot click on the UIButton and drag to the other. TOUCHES MOVED: Code: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event touchesForView:self.view] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(CGRectContainsPoint(oneButton.frame,

iPad: Measure/detect covered area by a finger touch on screen (NOT only touch coordinates)

♀尐吖头ヾ 提交于 2020-01-10 20:07:07
问题 I would like to get access to the area covered by a finger for each touch event on an IPad. Every touch event will result in a coordinate pair X and Y independent of how big the finger and consequently the touch area is that triggered the event. I was wondering if there is a way to get the area data which triggered the touch event e.g. size or coordinates NOT Any help is much appreciated. Thanks in advance for you answer or redirects, Christian 回答1: There is no public API for this. A private

Custom UINavigationBar's backButton?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-10 19:49:25
问题 I am making a iPhone app that allows the user to go back in a UINavigationBar. However, the way it looks now is horrendous. I am trying to customize it with my own image (minus the default UIBarButtonItem background). My image includes my custom background, but you can still see part of the button on the left and the right. UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_button_normal.png"] style:UIBarButtonItemStylePlain target:self action:

UITextView/UILabel with background but with spacing between lines

橙三吉。 提交于 2020-01-10 19:43:11
问题 How can I achieve this kind of style in iOS? I tried using NSAttributedString and setting NSBackgroundColorAttributeName as blackColor but then it doesn't have a clearColor space between the lines. I also tried to set a lineSpacing to the NSMutableParagraphStyle but still, the style looks like one big black block. I just need a hint in which way to go... thanks! In other words, not something like this: 回答1: After some research I found the best solution for what I needed. The solution below is

Change NSNumberFormatter's negative format from (xxx.xx) to -xxx.xx

不问归期 提交于 2020-01-10 19:26:55
问题 I want to change my NSNumberformatter from displaying negative numbers with parenthesis around them to putting the minus sign in front (or whatever the localized standard is). I would assume I could do this with setNegativeFormat: but reading Apple's oh so thorough docs I am left scratching my head: setNegativeFormat: Sets the format the receiver uses to display negative values. - (void)setNegativeFormat:(NSString *)aFormat Parameters aFormat A string that specifies the format for negative

Customising the font/background colour of index/section bar in UITableView

混江龙づ霸主 提交于 2020-01-10 17:33:10
问题 I've read in another thread on SO that you can adjust the font or background colour of the index bar (that is the A-Z # scrollbar) in a UITableView adding a CALayer. My app will be running on iOS 5 and above and since I haven't seen anything about this in the Apple docs, would it be right to say that it simply isn't possible without creating a custom table view? If this is possible (and acceptable to Apple), how would I go about doing this? 回答1: As of iOS 6.0 there are two methods that allow