开发者

How to sort array elements using x-axis values?

开发者 https://www.devze.com 2023-03-18 20:11 出处:网络
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

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

精彩评论

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