Question: so I am trying to implement the following. I have a view, which has a sentence. Only part of the sentence links to another view. This is what it looks like:

```
I am a cat. Learn More

```

The Learn More would be a link (blue in color), which when clicked would open another view.

Currently I am using a UILabel to write "I am a cat". I realize that the best way to add selectors is to use a button, so "Learn More" should be a button?

Is there any way to write this sentence out without using two different UIComponents? 

If not, then how do I make the UILabel and the UIButton completely horizontally aligned with each other?

The following is my code for the label in -layoutSubviews:

```
CGSize labelSize = [_label.text sizeWithFont:_label.font constrainedToSize:bounds.size lineBreakMode:_label.lineBreakMode];
  _label.frame = CGRectMake(0, 0, bounds.size.width - kMarginForText, labelSize.height);
  _label.center = CGPointMake(horizontalCenter, CGRectGetMaxY(_previousLabel.frame) + kDistanceBetweenPreviousAndCurrentLabel);

```

And the code for the label itself.

```
    _label = [[UILabel alloc] initWithFrame:CGRectZero];
    _label.text = "I am a cat";
    _label.font = [UIFont systemFontOfSize:14];
    _label.textAlignment = NSTextAlignmentCenter;
    _label.numberOfLines = 0;
    _label.lineBreakMode = UILineBreakModeWordWrap;
    [self addSubview:_label];

```

Any help would be appreciated!

Answer: 
You'll notice the javadoc of [`TreeMap`](http://docs.oracle.com/javase/7/docs/api/java/util/TreeMap.html) states

> 
> The map is sorted according to the natural ordering of its keys, or by
>  a Comparator provided at map creation time, depending on which
>  constructor is used.
> 
> 
> 

So if you don't provide a [`Comparator`](http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html), it will use *natural ordering*. What is natural ordering? The javadoc of the [`Comparable`](http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html) interface states

> 
> This interface imposes a total ordering on the objects of each class
>  that implements it. **This ordering is referred to as the class's
>  natural ordering,** and the class's compareTo method is referred to as
>  its natural comparison method.
> 
> 
> 

So your key element in your `TreeMap` must implement `Comparable`. You are trying to use `TreeSet` instances as keys in your `TreeMap`. [`TreeSet`](http://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html) does not implement `Comparable`.

You get a `ClassCastException` when `TreeMap` tries to cast the key to a `Comparable` reference in order to use its `compareTo` method. 

To correct this issue, you should create a `TreeMap` by providing your own custom `Comparator` for comparing `Set<Character>` instances.
Here's how you can create the comparator class:

```
public class NutrientByInclusionOrderComparator  implements Comparator<ProductNutrient>{

@Override
public int compare(ProductNutrient o1, ProductNutrient o2) {
    if (o1 == null && o2 == null){
        return 0;
    }
    else if (o1 == null){
        return -1;
    }
    else if (o2 == null){
        return 1;
    }
    else if ( o1.getNumOrder().compareTo(o2.getNumOrder()) == 0) {
        return o1.getDtInclusion().compareTo(o2.getDtInclusion());
    } else {
        return o1.getNumOrder().compareTo(o2.getNumOrder());
    }
}

}

```

And then, when creating your TreeSet:

```
Set<ProductNutrient> productNutrients = new TreeSet<ProductNutrient>(new NutrientByInclusionOrderComparator());

```

Cheers!