uibutton

 1. 自定义显示问题

一种是直接继承就可以了,增加点属性,然后用drawrect或则增加subviews

另外一种就是通过category增加unbutton的方法:

在我们的 .h file:

@interface UIButton (YourCategoryName)     - (void)setupButton:(NSString *)title image:(UIImage *)image description:(NSString *) description; @end

在我们的 .m file:

@implementation UIButton (YourCategoryName)

- void)setupButton:(NSString *)title image:(UIImage *)image description:(NSString *) description {     UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 200, 50)]];     [self addSubview:titleLabel];     [titleLabel release];     UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:image];     [self addSubview:imageView];     [imageView release];     UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 60, 200, 100)];     [self addSubview:descriptionLabel];     [descriptionLabel release]; }

  UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];   myButton.frame = CGRectMake(0, 0, 300, 200);   [myButton setupButton:myTitle image:myImage description:myDesc];

2. 关于边框问题
- (id)initWithFrame:(CGRect)frame {
if(self = [super initWithFrame:frame]) {         [self.layer setBorderWidth:1.0];         [self.layer setCornerRadius:5.0];         [self.layer setBorderColor:[[UIColor colorWithWhite:0.3 alpha:0.7] CGColor]]; } return self;}

如果你设置了背景图片,那么需要把边框放在背景图片中,否则border应该是不生效的

When you set a background image in a button, the button outlines go away. Include them in your image, if you need different sizes look at the UIImage

stretchableImageWithLeftCapWidth:topCapHeight:

method.

//数组快速过滤的方法

makeObjectsPerformSelector: is going to run that selector against every object in the array. If those objects are modified by the selector they will be modified. It does not return anything. Now, there is a catch, which that by default most copies in Cocoa are shallow copies, which means you get a new array, but the underlying objects it points to are the same objects. You will need to use initWithArray:copyItems to make it copy the root level items as well. If you want a new array containing the altered objects as well as the old array do something like this:

NSArray *newArray = [[NSArray alloc] initWithArray:oldArray copyItems:YES]; [newArray makeObjectsPerformSelector:@selector(doSomethingToObject:)];
排序

Use NSSortDescriptor like this..

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest"  ascending:YES];     [stories sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];     recent = [stories copy]; 

stories is the array you want to sort. recent is another mutable array which has sorted dictionary values. Change the @"interest" with the key value on which you have to sort.

如果是比较复杂的,需要再使用一个函数:

Write a sort function that compares the relevant fields in two dictionaries. When you have this version you can for example use NSArray#sortedArrayUsingFunction:context: to sort your array.

Seehttp://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BBCHBAHB

Suppose there are 2 keys, integers x ascending then and strings y descending, then you may write

NSSortDescriptor* dx = [[NSSortDescriptor alloc] initWithKey:@"x" ascending:YES]; NSSortDescriptor* dy = [[NSSortDescriptor alloc] initWithKey:@"y" ascending:NO selector:@selector(caseInsensitiveCompare:)]; [arr sortUsingDescriptors:[NSArray arrayWithObjects:x, y, nil]]; [dx release]; [dy release];

你可能感兴趣的:(image,cocoa,button,interface,Dictionary,Descriptor)