Accessibility label for UIImage in swift

Viewed 216

I have a UIImage and i need to use voice over to read the accessibility label . Currently voice over does not detect the string accessibilityLabel and just says "image" instead of the string . I am having hard time voice over to read userName instead of just image This how i am doing:

//username i am using for accessibility string

var userName: String {
     return "Ashton"
}

// the .image here is in the userNameModel is UIImage and not imageView

userNameModel.image.isAccessibilityElement = true
userNameModel.image.accessibilityLabel = userName

What am i doing wrong ?

1 Answers

For my understanding accessibility labels are mainly used for UI components. Maybe you need to use UIImageView and assign it the relevant data?

Related