How to sort array elements using x-axis values?
Actually I am getting the label values and x-coordinate and I need to sort the label values according to x-coordinate values. Can you please any one give me code how to 开发者_如何转开发do it. Thanks in advance..
This is one way to do it, you should be able to do it with keypaths a lot nicer.
[labels sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [[NSNumber numberWithFloat:[(UIView *)obj1 frame].origin.x] compare:[NSNumber numberWithFloat:[(UIView *)obj2 frame].origin.x]];
}];
精彩评论