cocoa-touch

How to draw an UIImage or directly in -drawRect:?

杀马特。学长 韩版系。学妹 提交于 2019-12-28 05:16:27
问题 I have an UIImage which I want to draw on a UIView . But instead of creating an UIImageView and adding this as a subview, I want to overwrite -drawRect: and draw my UIView directly. For example, my code looks like: - (void)drawRect:(CGRect)rect { CGContextRef myContext = UIGraphicsGetCurrentContext(); UIImage *img = [UIImage imageNamed:@"foo.png"]; // how to draw the directly into the view now? } 回答1: Call [img drawInRect:rect]; . 回答2: BTW, you shouldn't load the image file in the drawRect

How can I make deleteRowsAtIndexPaths: work with GenericTableViewController?

▼魔方 西西 提交于 2019-12-28 05:14:11
问题 I'm using Matt Gallagher's GenericTableViewController idea for controlling my UITableViews . My datasource is a NSFetchedResultsController . http://cocoawithlove.com/2008/12/heterogeneous-cells-in.html Everything is working fine, until I try to delete a cell. I have the following code in my View Controller: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle ==

UIView's border color in Interface builder doesn't work?

岁酱吖の 提交于 2019-12-28 04:58:06
问题 I am trying to set up a view's layer properties via IB. Everything works except for color of the border (property layer.borderColor ): I remember running into this problem a year ago and I ended up doing it programatically. And still, I can do this programmatically, but I am curious why the layer.borderColor property never works via interface builder. I don't want to import QuartzCore , and then write extra line of code just because of this, seems like an overkill. 回答1: It's possible to do

How do I remove the borders of a UITableView?

混江龙づ霸主 提交于 2019-12-28 04:54:36
问题 I have subclassed the UITableView control, and the style is grouped, but I do not need the cell separators. I tried setting my table view's separatorStyle to none, but it doesn't work. Can any one help me out? 回答1: In a grouped table view, setting separatorStyle doesn't do anything. If you want to hide it, just do the following: tableView.separatorColor = [UIColor clearColor]; 回答2: Use this tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 回答3: To remove the border of a table view

How to build an Objective-C static library?

倖福魔咒の 提交于 2019-12-28 04:51:08
问题 I have some Objective-C classes, which I am currently using in both a Cocoa application (Mac OS X) and a Cocoa-Touch application (iOS). Currently, when I update those classes, I have to copy those updated .h and .m files to both projects. Not that big of deal, but I'm going to be using them in many more projects. So, I want to build these classes into an Objective-C static library. And then link against that library in all other projects. Is there a way to build a static library such that it

How to build an Objective-C static library?

China☆狼群 提交于 2019-12-28 04:51:04
问题 I have some Objective-C classes, which I am currently using in both a Cocoa application (Mac OS X) and a Cocoa-Touch application (iOS). Currently, when I update those classes, I have to copy those updated .h and .m files to both projects. Not that big of deal, but I'm going to be using them in many more projects. So, I want to build these classes into an Objective-C static library. And then link against that library in all other projects. Is there a way to build a static library such that it

Looping using NSRange

∥☆過路亽.° 提交于 2019-12-28 04:20:13
问题 I'm trying to use NSRange to hold a range of years, such as NSRange years = NSMakeRange(2011, 5); I know NSRange is used mostly for filtering, however I want to loop over the elements in the range. Is that possible without converting the NSRange into a NSArray ? 回答1: It kind of sounds like you're expecting NSRange to be like a Python range object. It's not; NSRange is simply a struct typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; not an object. Once you've

Combining a UILongPressGestureRecognizer with a UIPanGestureRecognizer

╄→尐↘猪︶ㄣ 提交于 2019-12-28 04:02:11
问题 I d'like to combine a UILongPressGestureRecognizer with a UIPanGestureRecognizer. The UIPanGestureRecognizer should start with a long press. Is there a simple way to do this? or do I really have to write my own gesture recognizer? I wan't something like on the home screen. You press on an icon and after some time the icons start wobbling. Afterwards without releasing my finger from the screen I can start dragging the icon under my finger around. 回答1: actually, you don't have to combine

UIControlEventTouchDragExit triggers when 100 pixels away from UIButton

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-28 03:50:10
问题 At present, the UIControlEventTouchDragExit only triggers when I drag 100 pixels away from the button. I'd like to customize this behavior and bring that range in to around 25 pixels, but I'm relatively new to programming and have never needed to override / customize an in-built method like this. I've read in some other posts here that I'd need to subclass the UIButton (or perhaps even UIControl ?), and override -(BOOL) beginTrackingWithTouch: (UITouch *) touch withEvent: (UIEvent *) event

Offset on UIWindow addSubview

做~自己de王妃 提交于 2019-12-28 03:20:09
问题 I've got a UITabBar based application that works just fine. Under certain circumstances I am showing a different UIViewController instead though. Now what bugs me is that that I have to adjust the frame for the Test nib (and only the Test nib!) to display correctly. (Otherwise the view is below the status bar). - (void)applicationDidFinishLaunching:(UIApplication *)application { if (condition) { UIViewController *vc = [[UIViewController alloc] initWithNibName:@"Test" bundle:nil]; // FIXME