The answer may depend on whether or not you mean that you wish to drive the rental
car into the UK (and bring it back to Spain) or whether you wish to drop off the rental car in the UK.
I checked for any driving restriction for cars rented in Spain. There are no restrictions regarding driving into the United Kingdom. There are geographic restrictions for other countries, as follows:
Cars rented in Spain are NOT allowed into the following countries: Albania, Bosnia, Belarus, Bulgaria, Czech Republic, Croatia, Estonia, Greece, Hungary, Latvia, Lithuania, Macedonia, Montenegro, Poland, Russia, Slovakia, Slovenia, Turkey, Ukraine and Yugoslavia.
AutoEurope.com -- Car Rental Guide for Spain
If you want to drop off the rental car in the UK and not return it back to Spain, this may or may not be allowed, depending on the car rental company. You would have to check for availability for one way rentals, based on your specific city, dates and times of pickup and drop off, and what size or type of car you're looking for. You would need to check with each car rental company to see who will allow the hire of a car from Barcelona to be driven to the UK, if the hire car is not to be returned to Barcelona.