开发者

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]];
}];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜